From 114d6f3499ce77f12313dd444a2051f6dfc701f2 Mon Sep 17 00:00:00 2001 From: dashjay Date: Sat, 2 May 2026 04:37:08 +0800 Subject: [PATCH 1/2] refactor dir --- hack/update-doc.sh | 18 +- hack/verify-doc.sh | 36 +++ {pkg/internal => internal}/README.md | 18 +- .../constraints/constraints.go | 0 {pkg/internal => internal}/utils/utils.go | 0 {pkg/internal => internal}/xassert/xassert.go | 2 +- .../xassert/xassert_test.go | 2 +- {pkg/optional => optional}/README.md | 20 +- {pkg/optional => optional}/doc.go | 0 {pkg/optional => optional}/optional.go | 0 {pkg/optional => optional}/optional_test.go | 2 +- {pkg/union => union}/README.md | 22 +- {pkg/union => union}/union.go | 0 {pkg/xcmp => xcmp}/README.md | 18 +- {pkg/xcmp => xcmp}/xcmd_old.go | 0 {pkg/xcmp => xcmp}/xcmp.go | 0 {pkg/xcmp => xcmp}/xcmp_test.go | 2 +- {pkg/xiter => xiter}/README.md | 206 +++++++++--------- {pkg/xiter => xiter}/doc.go | 0 {pkg/xiter => xiter}/xiter.go | 10 +- {pkg/xiter => xiter}/xiter_benchmark_test.go | 2 +- {pkg/xiter => xiter}/xiter_common.go | 6 +- {pkg/xiter => xiter}/xiter_common_test.go | 2 +- {pkg/xiter => xiter}/xiter_old.go | 10 +- {pkg/xiter => xiter}/xiter_pull_test.go | 2 +- {pkg/xiter => xiter}/xiter_test.go | 6 +- {pkg/xmap => xmap}/README.md | 50 ++--- {pkg/xmap => xmap}/xmap.go | 2 +- {pkg/xmap => xmap}/xmap_benchmark_test.go | 2 +- {pkg/xmap => xmap}/xmap_common.go | 8 +- {pkg/xmap => xmap}/xmap_old.go | 2 +- {pkg/xmap => xmap}/xmap_test.go | 6 +- {pkg/xslice => xslice}/README.md | 138 ++++++------ {pkg/xslice => xslice}/doc.go | 0 {pkg/xslice => xslice}/xslice.go | 8 +- .../xslice_benchmark_test.go | 2 +- {pkg/xslice => xslice}/xslice_test.go | 8 +- {pkg/xstl => xstl}/README.md | 44 ++-- {pkg/xstl => xstl}/list/example_test.go | 2 +- {pkg/xstl => xstl}/list/list.go | 0 {pkg/xstl => xstl}/list/list_test.go | 0 {pkg/xsync => xsync}/README.md | 74 +++---- {pkg/xsync => xsync}/doc.go | 0 {pkg/xsync => xsync}/locked_value.go | 0 {pkg/xsync => xsync}/locked_value_test.go | 0 {pkg/xsync => xsync}/sync_map.go | 0 {pkg/xsync => xsync}/sync_map_1_20.go | 0 {pkg/xsync => xsync}/sync_map_1_20_test.go | 2 +- {pkg/xsync => xsync}/sync_map_1_23.go | 0 {pkg/xsync => xsync}/sync_map_1_23_test.go | 2 +- {pkg/xsync => xsync}/sync_map_test.go | 2 +- {pkg/xsync => xsync}/sync_pool.go | 0 {pkg/xsync => xsync}/sync_pool_test.go | 2 +- 53 files changed, 388 insertions(+), 350 deletions(-) mode change 100644 => 100755 hack/verify-doc.sh rename {pkg/internal => internal}/README.md (61%) rename {pkg/internal => internal}/constraints/constraints.go (100%) rename {pkg/internal => internal}/utils/utils.go (100%) rename {pkg/internal => internal}/xassert/xassert.go (76%) rename {pkg/internal => internal}/xassert/xassert_test.go (83%) rename {pkg/optional => optional}/README.md (84%) rename {pkg/optional => optional}/doc.go (100%) rename {pkg/optional => optional}/optional.go (100%) rename {pkg/optional => optional}/optional_test.go (93%) rename {pkg/union => union}/README.md (67%) rename {pkg/union => union}/union.go (100%) rename {pkg/xcmp => xcmp}/README.md (85%) rename {pkg/xcmp => xcmp}/xcmd_old.go (100%) rename {pkg/xcmp => xcmp}/xcmp.go (100%) rename {pkg/xcmp => xcmp}/xcmp_test.go (99%) rename {pkg/xiter => xiter}/README.md (85%) rename {pkg/xiter => xiter}/doc.go (100%) rename {pkg/xiter => xiter}/xiter.go (99%) rename {pkg/xiter => xiter}/xiter_benchmark_test.go (96%) rename {pkg/xiter => xiter}/xiter_common.go (98%) rename {pkg/xiter => xiter}/xiter_common_test.go (99%) rename {pkg/xiter => xiter}/xiter_old.go (98%) rename {pkg/xiter => xiter}/xiter_pull_test.go (99%) rename {pkg/xiter => xiter}/xiter_test.go (99%) rename {pkg/xmap => xmap}/README.md (89%) rename {pkg/xmap => xmap}/xmap.go (96%) rename {pkg/xmap => xmap}/xmap_benchmark_test.go (97%) rename {pkg/xmap => xmap}/xmap_common.go (98%) rename {pkg/xmap => xmap}/xmap_old.go (97%) rename {pkg/xmap => xmap}/xmap_test.go (99%) rename {pkg/xslice => xslice}/README.md (84%) rename {pkg/xslice => xslice}/doc.go (100%) rename {pkg/xslice => xslice}/xslice.go (99%) rename {pkg/xslice => xslice}/xslice_benchmark_test.go (99%) rename {pkg/xslice => xslice}/xslice_test.go (99%) rename {pkg/xstl => xstl}/README.md (86%) rename {pkg/xstl => xstl}/list/example_test.go (92%) rename {pkg/xstl => xstl}/list/list.go (100%) rename {pkg/xstl => xstl}/list/list_test.go (100%) rename {pkg/xsync => xsync}/README.md (84%) rename {pkg/xsync => xsync}/doc.go (100%) rename {pkg/xsync => xsync}/locked_value.go (100%) rename {pkg/xsync => xsync}/locked_value_test.go (100%) rename {pkg/xsync => xsync}/sync_map.go (100%) rename {pkg/xsync => xsync}/sync_map_1_20.go (100%) rename {pkg/xsync => xsync}/sync_map_1_20_test.go (97%) rename {pkg/xsync => xsync}/sync_map_1_23.go (100%) rename {pkg/xsync => xsync}/sync_map_1_23_test.go (92%) rename {pkg/xsync => xsync}/sync_map_test.go (98%) rename {pkg/xsync => xsync}/sync_pool.go (100%) rename {pkg/xsync => xsync}/sync_pool_test.go (85%) diff --git a/hack/update-doc.sh b/hack/update-doc.sh index 8ad3b1c..6436047 100755 --- a/hack/update-doc.sh +++ b/hack/update-doc.sh @@ -10,11 +10,13 @@ ROOT_DIR="$SCRIPT_DIR"/.. cd "$ROOT_DIR" -for i in $(ls pkg/) -do $(go env GOPATH)/bin/gomarkdoc \ - --repository.url=https://github.com/dashjay/xiter \ - --repository.default-branch=main \ - ./pkg/$i/... \ - --output \ - ./pkg/$i/README.md -done +while IFS= read -r -d '' dir; do + i=$(basename "$dir") + [[ "$i" == "hack" || "$i" == "doc" || "$i" == ".git" ]] && continue + $(go env GOPATH)/bin/gomarkdoc \ + --repository.url=https://github.com/dashjay/xiter \ + --repository.default-branch=main \ + ./$i/... \ + --output \ + ./$i/README.md +done < <(find . -maxdepth 1 -type d -not -name '.' -print0) diff --git a/hack/verify-doc.sh b/hack/verify-doc.sh old mode 100644 new mode 100755 index e69de29..95d2388 --- a/hack/verify-doc.sh +++ b/hack/verify-doc.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail +set -o errtrace + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +ROOT_DIR="$SCRIPT_DIR"/.. + +cd "$ROOT_DIR" + +# Generate docs into a temp directory and diff against committed docs +tmpdir=$(mktemp -d) +trap 'rm -rf "$tmpdir"' EXIT + +while IFS= read -r -d '' dir; do + i=$(basename "$dir") + [[ "$i" == "hack" || "$i" == "doc" || "$i" == ".git" ]] && continue + mkdir -p "$tmpdir/$i" + $(go env GOPATH)/bin/gomarkdoc \ + --repository.url=https://github.com/dashjay/xiter \ + --repository.default-branch=main \ + ./$i/... \ + --output \ + "$tmpdir/$i/README.md" + if [ -f "$tmpdir/$i/README.md" ]; then + if ! diff -q "./$i/README.md" "$tmpdir/$i/README.md" &>/dev/null; then + echo "ERROR: $i/README.md is out of date. Run hack/update-doc.sh to regenerate." + diff "./$i/README.md" "$tmpdir/$i/README.md" + exit 1 + fi + fi +done < <(find . -maxdepth 1 -type d -not -name '.' -print0) + +echo "All docs are up to date." diff --git a/pkg/internal/README.md b/internal/README.md similarity index 61% rename from pkg/internal/README.md rename to internal/README.md index d09d61e..2d31d6a 100644 --- a/pkg/internal/README.md +++ b/internal/README.md @@ -3,7 +3,7 @@ # constraints ```go -import "github.com/dashjay/xiter/pkg/internal/constraints" +import "github.com/dashjay/xiter/internal/constraints" ``` Package constraints defined constraints for generics tools @@ -17,7 +17,7 @@ Package constraints defined constraints for generics tools -## type [Float]() +## type [Float]() @@ -28,7 +28,7 @@ type Float interface { ``` -## type [Integer]() +## type [Integer]() @@ -39,7 +39,7 @@ type Integer interface { ``` -## type [Number]() +## type [Number]() @@ -50,7 +50,7 @@ type Number interface { ``` -## type [Ordered]() +## type [Ordered]() @@ -63,7 +63,7 @@ type Ordered interface { # utils ```go -import "github.com/dashjay/xiter/pkg/internal/utils" +import "github.com/dashjay/xiter/internal/utils" ``` ## Index @@ -72,7 +72,7 @@ import "github.com/dashjay/xiter/pkg/internal/utils" -## func [IsZero]() +## func [IsZero]() ```go func IsZero[T comparable](v T) bool @@ -83,7 +83,7 @@ func IsZero[T comparable](v T) bool # xassert ```go -import "github.com/dashjay/xiter/pkg/internal/xassert" +import "github.com/dashjay/xiter/internal/xassert" ``` ## Index @@ -92,7 +92,7 @@ import "github.com/dashjay/xiter/pkg/internal/xassert" -## func [MustBePositive]() +## func [MustBePositive]() ```go func MustBePositive[T constraints.Number](in T) diff --git a/pkg/internal/constraints/constraints.go b/internal/constraints/constraints.go similarity index 100% rename from pkg/internal/constraints/constraints.go rename to internal/constraints/constraints.go diff --git a/pkg/internal/utils/utils.go b/internal/utils/utils.go similarity index 100% rename from pkg/internal/utils/utils.go rename to internal/utils/utils.go diff --git a/pkg/internal/xassert/xassert.go b/internal/xassert/xassert.go similarity index 76% rename from pkg/internal/xassert/xassert.go rename to internal/xassert/xassert.go index afbe198..b8a7d30 100644 --- a/pkg/internal/xassert/xassert.go +++ b/internal/xassert/xassert.go @@ -3,7 +3,7 @@ package xassert import ( "fmt" - "github.com/dashjay/xiter/pkg/internal/constraints" + "github.com/dashjay/xiter/internal/constraints" ) func MustBePositive[T constraints.Number](in T) { diff --git a/pkg/internal/xassert/xassert_test.go b/internal/xassert/xassert_test.go similarity index 83% rename from pkg/internal/xassert/xassert_test.go rename to internal/xassert/xassert_test.go index dd897f2..0f157a4 100644 --- a/pkg/internal/xassert/xassert_test.go +++ b/internal/xassert/xassert_test.go @@ -3,7 +3,7 @@ package xassert_test import ( "testing" - "github.com/dashjay/xiter/pkg/internal/xassert" + "github.com/dashjay/xiter/internal/xassert" "github.com/stretchr/testify/assert" ) diff --git a/pkg/optional/README.md b/optional/README.md similarity index 84% rename from pkg/optional/README.md rename to optional/README.md index 18bc9e7..d14bf68 100644 --- a/pkg/optional/README.md +++ b/optional/README.md @@ -3,7 +3,7 @@ # optional ```go -import "github.com/dashjay/xiter/pkg/optional" +import "github.com/dashjay/xiter/optional" ``` Package optional provides a type which can be used to represent a value that may or may not be present like option in Rust. @@ -22,7 +22,7 @@ Package optional provides a type which can be used to represent a value that may -## type [O]() +## type [O]() @@ -33,7 +33,7 @@ type O[T any] struct { ``` -### func [Empty]() +### func [Empty]() ```go func Empty[T any]() O[T] @@ -42,7 +42,7 @@ func Empty[T any]() O[T] Empty creates an empty Optional with no value. -### func [FromValue]() +### func [FromValue]() ```go func FromValue[T any](v T) O[T] @@ -51,7 +51,7 @@ func FromValue[T any](v T) O[T] FromValue creates an Optional from a value. -### func [FromValue2]() +### func [FromValue2]() ```go func FromValue2[T any](v T, ok bool) O[T] @@ -68,7 +68,7 @@ if v, ok := fn(); ok { FromValue(v) } else { Empty[T]() } ``` -### func \(O\[T\]\) [Must]() +### func \(O\[T\]\) [Must]() ```go func (o O[T]) Must() T @@ -79,7 +79,7 @@ Must directly return the value of the Optional. ❌WARNING: Panic if the Optional has no value. -### func \(O\[T\]\) [Ok]() +### func \(O\[T\]\) [Ok]() ```go func (o O[T]) Ok() bool @@ -88,7 +88,7 @@ func (o O[T]) Ok() bool Ok returns whether the Optional has a valid value. -### func \(O\[T\]\) [Ptr]() +### func \(O\[T\]\) [Ptr]() ```go func (o O[T]) Ptr() *T @@ -97,7 +97,7 @@ func (o O[T]) Ptr() *T Ptr returns a pointer to the value of the Optional. return nil if the Optional has no value. -### func \(O\[T\]\) [ValueOr]() +### func \(O\[T\]\) [ValueOr]() ```go func (o O[T]) ValueOr(dft T) T @@ -106,7 +106,7 @@ func (o O[T]) ValueOr(dft T) T ValueOr returns the value of the Optional if it has a valid value, otherwise returns the given default value. -### func \(O\[T\]\) [ValueOrZero]() +### func \(O\[T\]\) [ValueOrZero]() ```go func (o O[T]) ValueOrZero() T diff --git a/pkg/optional/doc.go b/optional/doc.go similarity index 100% rename from pkg/optional/doc.go rename to optional/doc.go diff --git a/pkg/optional/optional.go b/optional/optional.go similarity index 100% rename from pkg/optional/optional.go rename to optional/optional.go diff --git a/pkg/optional/optional_test.go b/optional/optional_test.go similarity index 93% rename from pkg/optional/optional_test.go rename to optional/optional_test.go index af876b1..9ef81c1 100644 --- a/pkg/optional/optional_test.go +++ b/optional/optional_test.go @@ -3,7 +3,7 @@ package optional_test import ( "testing" - "github.com/dashjay/xiter/pkg/optional" + "github.com/dashjay/xiter/optional" "github.com/stretchr/testify/assert" ) diff --git a/pkg/union/README.md b/union/README.md similarity index 67% rename from pkg/union/README.md rename to union/README.md index e32620a..bbc5b13 100644 --- a/pkg/union/README.md +++ b/union/README.md @@ -3,7 +3,7 @@ # union ```go -import "github.com/dashjay/xiter/pkg/union" +import "github.com/dashjay/xiter/union" ``` ## Index @@ -21,7 +21,7 @@ import "github.com/dashjay/xiter/pkg/union" -## type [U10]() +## type [U10]() @@ -41,7 +41,7 @@ type U10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any] struct { ``` -## type [U11]() +## type [U11]() @@ -62,7 +62,7 @@ type U11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any] struct { ``` -## type [U2]() +## type [U2]() @@ -74,7 +74,7 @@ type U2[T1, T2 any] struct { ``` -## type [U3]() +## type [U3]() @@ -87,7 +87,7 @@ type U3[T1, T2, T3 any] struct { ``` -## type [U4]() +## type [U4]() @@ -101,7 +101,7 @@ type U4[T1, T2, T3, T4 any] struct { ``` -## type [U5]() +## type [U5]() @@ -116,7 +116,7 @@ type U5[T1, T2, T3, T4, T5 any] struct { ``` -## type [U6]() +## type [U6]() @@ -132,7 +132,7 @@ type U6[T1, T2, T3, T4, T5, T6 any] struct { ``` -## type [U7]() +## type [U7]() @@ -149,7 +149,7 @@ type U7[T1, T2, T3, T4, T5, T6, T7 any] struct { ``` -## type [U8]() +## type [U8]() @@ -167,7 +167,7 @@ type U8[T1, T2, T3, T4, T5, T6, T7, T8 any] struct { ``` -## type [U9]() +## type [U9]() diff --git a/pkg/union/union.go b/union/union.go similarity index 100% rename from pkg/union/union.go rename to union/union.go diff --git a/pkg/xcmp/README.md b/xcmp/README.md similarity index 85% rename from pkg/xcmp/README.md rename to xcmp/README.md index 72db7a6..ea29571 100644 --- a/pkg/xcmp/README.md +++ b/xcmp/README.md @@ -3,7 +3,7 @@ # xcmp ```go -import "github.com/dashjay/xiter/pkg/xcmp" +import "github.com/dashjay/xiter/xcmp" ``` ## Index @@ -15,7 +15,7 @@ import "github.com/dashjay/xiter/pkg/xcmp" -## func [Compare]() +## func [Compare]() ```go func Compare[T Ordered](x, y T) int @@ -35,7 +35,7 @@ import ( "fmt" "math" - "github.com/dashjay/xiter/pkg/xcmp" + "github.com/dashjay/xiter/xcmp" ) func main() { @@ -59,7 +59,7 @@ func main() { -## func [Less]() +## func [Less]() ```go func Less[T Ordered](x, y T) bool @@ -79,7 +79,7 @@ import ( "fmt" "math" - "github.com/dashjay/xiter/pkg/xcmp" + "github.com/dashjay/xiter/xcmp" ) func main() { @@ -103,7 +103,7 @@ true -## func [Or]() +## func [Or]() ```go func Or[T comparable](vals ...T) T @@ -122,7 +122,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xcmp" + "github.com/dashjay/xiter/xcmp" ) func main() { @@ -161,7 +161,7 @@ import ( "sort" "strings" - "github.com/dashjay/xiter/pkg/xcmp" + "github.com/dashjay/xiter/xcmp" ) type Order struct { @@ -233,7 +233,7 @@ baz carol 4.00 -## type [Ordered]() +## type [Ordered]() diff --git a/pkg/xcmp/xcmd_old.go b/xcmp/xcmd_old.go similarity index 100% rename from pkg/xcmp/xcmd_old.go rename to xcmp/xcmd_old.go diff --git a/pkg/xcmp/xcmp.go b/xcmp/xcmp.go similarity index 100% rename from pkg/xcmp/xcmp.go rename to xcmp/xcmp.go diff --git a/pkg/xcmp/xcmp_test.go b/xcmp/xcmp_test.go similarity index 99% rename from pkg/xcmp/xcmp_test.go rename to xcmp/xcmp_test.go index 375767f..5c7e6a7 100644 --- a/pkg/xcmp/xcmp_test.go +++ b/xcmp/xcmp_test.go @@ -13,7 +13,7 @@ import ( "testing" "unsafe" - "github.com/dashjay/xiter/pkg/xcmp" + "github.com/dashjay/xiter/xcmp" ) var negzero = math.Copysign(0, -1) diff --git a/pkg/xiter/README.md b/xiter/README.md similarity index 85% rename from pkg/xiter/README.md rename to xiter/README.md index b32822f..22951ba 100644 --- a/pkg/xiter/README.md +++ b/xiter/README.md @@ -3,7 +3,7 @@ # xiter ```go -import "github.com/dashjay/xiter/pkg/xiter" +import "github.com/dashjay/xiter/xiter" ``` Package xiter provides the abstraction of map, slice or channel types into iterators for common processing In most scenarios, we DO NOT need to use the xiter package directly @@ -107,7 +107,7 @@ WARNING: golang 1.23 has higher performance on iterating Seq/Seq2 which boost by -## func [AllFromSeq]() +## func [AllFromSeq]() ```go func AllFromSeq[T any](seq Seq[T], f func(T) bool) bool @@ -116,7 +116,7 @@ func AllFromSeq[T any](seq Seq[T], f func(T) bool) bool AllFromSeq return true if all elements from seq satisfy the condition evaluated by f. -## func [AnyFromSeq]() +## func [AnyFromSeq]() ```go func AnyFromSeq[T any](seq Seq[T], f func(T) bool) bool @@ -125,7 +125,7 @@ func AnyFromSeq[T any](seq Seq[T], f func(T) bool) bool AnyFromSeq return true if any elements from seq satisfy the condition evaluated by f. -## func [At]() +## func [At]() ```go func At[T any](seq Seq[T], index int) optional.O[T] @@ -134,7 +134,7 @@ func At[T any](seq Seq[T], index int) optional.O[T] At return the element at index from seq. -## func [AvgByFromSeq]() +## func [AvgByFromSeq]() ```go func AvgByFromSeq[V any, T constraints.Number](seq Seq[V], f func(V) T) float64 @@ -143,7 +143,7 @@ func AvgByFromSeq[V any, T constraints.Number](seq Seq[V], f func(V) T) float64 AvgByFromSeq return the average value of all elements from seq, evaluated by f. -## func [AvgFromSeq]() +## func [AvgFromSeq]() ```go func AvgFromSeq[T constraints.Number](seq Seq[T]) float64 @@ -152,7 +152,7 @@ func AvgFromSeq[T constraints.Number](seq Seq[T]) float64 AvgFromSeq return the average value of all elements from seq. -## func [Contains]() +## func [Contains]() ```go func Contains[T comparable](seq Seq[T], in T) bool @@ -161,7 +161,7 @@ func Contains[T comparable](seq Seq[T], in T) bool Contains return true if v is in seq. -## func [ContainsAll]() +## func [ContainsAll]() ```go func ContainsAll[T comparable](seq Seq[T], in []T) bool @@ -170,7 +170,7 @@ func ContainsAll[T comparable](seq Seq[T], in []T) bool ContainsAll return true if all elements from seq is in vs. -## func [ContainsAny]() +## func [ContainsAny]() ```go func ContainsAny[T comparable](seq Seq[T], in []T) bool @@ -179,7 +179,7 @@ func ContainsAny[T comparable](seq Seq[T], in []T) bool ContainsAny return true if any element from seq is in vs. -## func [ContainsBy]() +## func [ContainsBy]() ```go func ContainsBy[T any](seq Seq[T], f func(T) bool) bool @@ -188,7 +188,7 @@ func ContainsBy[T any](seq Seq[T], f func(T) bool) bool ContainsBy return true if any element from seq satisfies the condition evaluated by f. -## func [Count]() +## func [Count]() ```go func Count[T any](seq Seq[T]) int @@ -197,7 +197,7 @@ func Count[T any](seq Seq[T]) int Count return the number of elements in seq. -## func [Difference]() +## func [Difference]() ```go func Difference[T comparable](left Seq[T], right Seq[T]) (onlyLeft Seq[T], onlyRight Seq[T]) @@ -216,7 +216,7 @@ onlyLeft, onlyRight := Difference(FromSlice(left), FromSlice(right)) ``` -## func [Equal]() +## func [Equal]() ```go func Equal[V comparable](x, y Seq[V]) bool @@ -248,7 +248,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -271,7 +271,7 @@ false -## func [Equal2]() +## func [Equal2]() ```go func Equal2[K, V comparable](x, y Seq2[K, V]) bool @@ -280,7 +280,7 @@ func Equal2[K, V comparable](x, y Seq2[K, V]) bool Equal2 returns whether the two Seq2 are equal. Like Equal but run with Seq2 -## func [EqualFunc]() +## func [EqualFunc]() ```go func EqualFunc[V1, V2 any](x Seq[V1], y Seq[V2], f func(V1, V2) bool) bool @@ -314,7 +314,7 @@ import ( "fmt" "math" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -340,7 +340,7 @@ false -## func [EqualFunc2]() +## func [EqualFunc2]() ```go func EqualFunc2[K1, V1, K2, V2 any](x Seq2[K1, V1], y Seq2[K2, V2], f func(K1, V1, K2, V2) bool) bool @@ -349,7 +349,7 @@ func EqualFunc2[K1, V1, K2, V2 any](x Seq2[K1, V1], y Seq2[K2, V2], f func(K1, V EqualFunc2 returns whether the two sequences are equal according to the function f. Like EqualFunc but run with Seq2 -## func [Find]() +## func [Find]() ```go func Find[T any](seq Seq[T], f func(T) bool) (val T, found bool) @@ -358,7 +358,7 @@ func Find[T any](seq Seq[T], f func(T) bool) (val T, found bool) Find return the first element from seq that satisfies the condition evaluated by f with a boolean representing whether it exists. -## func [FindO]() +## func [FindO]() ```go func FindO[T any](seq Seq[T], f func(T) bool) optional.O[T] @@ -367,7 +367,7 @@ func FindO[T any](seq Seq[T], f func(T) bool) optional.O[T] FindO return the first element from seq that satisfies the condition evaluated by f. -## func [First]() +## func [First]() ```go func First[T any](in Seq[T]) (T, bool) @@ -382,7 +382,7 @@ first, ok := First(seq) ``` -## func [FirstO]() +## func [FirstO]() ```go func FirstO[T any](in Seq[T]) optional.O[T] @@ -397,7 +397,7 @@ first, ok := FirstO(seq) ``` -## func [ForEach]() +## func [ForEach]() ```go func ForEach[T any](seq Seq[T], f func(T) bool) @@ -406,7 +406,7 @@ func ForEach[T any](seq Seq[T], f func(T) bool) ForEach execute f for each element in seq. -## func [ForEachIdx]() +## func [ForEachIdx]() ```go func ForEachIdx[T any](seq Seq[T], f func(idx int, v T) bool) @@ -415,7 +415,7 @@ func ForEachIdx[T any](seq Seq[T], f func(idx int, v T) bool) ForEachIdx execute f for each element in seq with its index. -## func [Head]() +## func [Head]() ```go func Head[T any](seq Seq[T]) (v T, hasOne bool) @@ -424,7 +424,7 @@ func Head[T any](seq Seq[T]) (v T, hasOne bool) Head return the first element from seq with a boolean representing whether it is at least one element in seq. -## func [HeadO]() +## func [HeadO]() ```go func HeadO[T any](seq Seq[T]) optional.O[T] @@ -433,7 +433,7 @@ func HeadO[T any](seq Seq[T]) optional.O[T] HeadO return the first element from seq. -## func [Index]() +## func [Index]() ```go func Index[T comparable](seq Seq[T], v T) int @@ -450,7 +450,7 @@ idx := xiter.Index(seq, 3) ``` -## func [Join]() +## func [Join]() ```go func Join[T ~string](seq Seq[T], sep T) T @@ -459,7 +459,7 @@ func Join[T ~string](seq Seq[T], sep T) T Join return the concatenation of all elements in seq with sep. -## func [Last]() +## func [Last]() ```go func Last[T any](in Seq[T]) (T, bool) @@ -474,7 +474,7 @@ last, ok := Last(seq) ``` -## func [LastO]() +## func [LastO]() ```go func LastO[T any](in Seq[T]) optional.O[T] @@ -489,7 +489,7 @@ last, ok := LastO(seq) ``` -## func [Max]() +## func [Max]() ```go func Max[T constraints.Ordered](seq Seq[T]) (r optional.O[T]) @@ -498,7 +498,7 @@ func Max[T constraints.Ordered](seq Seq[T]) (r optional.O[T]) Max returns the maximum element in seq. -## func [MaxBy]() +## func [MaxBy]() ```go func MaxBy[T any](seq Seq[T], less func(T, T) bool) (r optional.O[T]) @@ -507,7 +507,7 @@ func MaxBy[T any](seq Seq[T], less func(T, T) bool) (r optional.O[T]) MaxBy return the maximum element in seq, evaluated by f. -## func [Mean]() +## func [Mean]() ```go func Mean[T constraints.Number](in Seq[T]) T @@ -523,7 +523,7 @@ mean := Mean(FromSlice([]int{1, 2, 3, 4, 5})) ``` -## func [MeanBy]() +## func [MeanBy]() ```go func MeanBy[T any, R constraints.Number](in Seq[T], fn func(T) R) R @@ -541,7 +541,7 @@ mean := MeanBy(FromSlice([]int{1, 2, 3, 4, 5}), func(v int) int { ``` -## func [Min]() +## func [Min]() ```go func Min[T constraints.Ordered](seq Seq[T]) (r optional.O[T]) @@ -550,7 +550,7 @@ func Min[T constraints.Ordered](seq Seq[T]) (r optional.O[T]) Min return the minimum element in seq. -## func [MinBy]() +## func [MinBy]() ```go func MinBy[T any](seq Seq[T], less func(T, T) bool) (r optional.O[T]) @@ -559,7 +559,7 @@ func MinBy[T any](seq Seq[T], less func(T, T) bool) (r optional.O[T]) MinBy return the minimum element in seq, evaluated by f. -## func [Moderate]() +## func [Moderate]() ```go func Moderate[T comparable](in Seq[T]) (T, bool) @@ -575,7 +575,7 @@ moderate := Moderate(FromSlice([]int{1, 2, 3, 4, 5, 5, 5, 6, 6, 6, 6})) ``` -## func [ModerateO]() +## func [ModerateO]() ```go func ModerateO[T constraints.Number](in Seq[T]) optional.O[T] @@ -591,7 +591,7 @@ moderate := ModerateO(FromSlice([]int{1, 2, 3, 4, 5, 5, 5, 6, 6, 6, 6})) ``` -## func [Pull]() +## func [Pull]() ```go func Pull[V any](seq Seq[V]) (next func() (V, bool), stop func()) @@ -620,7 +620,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -642,7 +642,7 @@ func main() { -## func [Pull2]() +## func [Pull2]() ```go func Pull2[K, V any](seq Seq2[K, V]) (next func() (K, V, bool), stop func()) @@ -651,7 +651,7 @@ func Pull2[K, V any](seq Seq2[K, V]) (next func() (K, V, bool), stop func()) -## func [Reduce]() +## func [Reduce]() ```go func Reduce[Sum, V any](f func(Sum, V) Sum, sum Sum, seq Seq[V]) Sum @@ -680,7 +680,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func _range(a, b int) []int { @@ -710,7 +710,7 @@ func main() { -## func [Reduce2]() +## func [Reduce2]() ```go func Reduce2[Sum, K, V any](f func(Sum, K, V) Sum, sum Sum, seq Seq2[K, V]) Sum @@ -719,7 +719,7 @@ func Reduce2[Sum, K, V any](f func(Sum, K, V) Sum, sum Sum, seq Seq2[K, V]) Sum Reduce2 combines the values in seq using f. For each pair k, v in seq, it updates sum = f\(sum, k, v\) and then returns the final sum. For example, if iterating over seq yields \(k1, v1\), \(k2, v2\), \(k3, v3\) Reduce returns f\(f\(f\(sum, k1, v1\), k2, v2\), k3, v3\). -## func [Sum]() +## func [Sum]() ```go func Sum[T constraints.Number](seq Seq[T]) T @@ -736,7 +736,7 @@ sum := xiter.Sum(seq) ``` -## func [ToChan]() +## func [ToChan]() ```go func ToChan[T any](seq Seq[T]) <-chan T @@ -755,7 +755,7 @@ for v := range ch { ``` -## func [ToMap]() +## func [ToMap]() ```go func ToMap[K comparable, V any](seq Seq2[K, V]) (out map[K]V) @@ -764,7 +764,7 @@ func ToMap[K comparable, V any](seq Seq2[K, V]) (out map[K]V) -## func [ToMapFromSeq]() +## func [ToMapFromSeq]() ```go func ToMapFromSeq[K comparable, V any](seq Seq[K], fn func(k K) V) (out map[K]V) @@ -773,7 +773,7 @@ func ToMapFromSeq[K comparable, V any](seq Seq[K], fn func(k K) V) (out map[K]V) -## func [ToSlice]() +## func [ToSlice]() ```go func ToSlice[T any](seq Seq[T]) (out []T) @@ -782,7 +782,7 @@ func ToSlice[T any](seq Seq[T]) (out []T) ToSlice returns the elements in seq as a slice. -## func [ToSliceN]() +## func [ToSliceN]() ```go func ToSliceN[T any](seq Seq[T], n int) (out []T) @@ -791,7 +791,7 @@ func ToSliceN[T any](seq Seq[T], n int) (out []T) ToSliceN pull out n elements from seq. -## func [ToSliceSeq2Key]() +## func [ToSliceSeq2Key]() ```go func ToSliceSeq2Key[K, V any](seq Seq2[K, V]) (out []K) @@ -808,7 +808,7 @@ keys := ToSliceSeq2Key(seq) ``` -## func [ToSliceSeq2Value]() +## func [ToSliceSeq2Value]() ```go func ToSliceSeq2Value[K, V any](seq Seq2[K, V]) (out []V) @@ -825,7 +825,7 @@ values := ToSliceSeq2Value(seq) ``` -## type [Seq]() +## type [Seq]() Seq is a sequence of elements provided by an iterator\-like function. We made this alias Seq to iter.Seq for providing a compatible interface in lower go versions. @@ -834,7 +834,7 @@ type Seq[V any] iter.Seq[V] ``` -### func [Chunk]() +### func [Chunk]() ```go func Chunk[T any](seq Seq[T], n int) Seq[[]T] @@ -851,7 +851,7 @@ chunkedSeq := xiter.Chunk(seq, 2) ``` -### func [Compact]() +### func [Compact]() ```go func Compact[T comparable](in Seq[T]) Seq[T] @@ -866,7 +866,7 @@ Compact([]int{0, 1, 2, 3, 4}) πŸ‘‰ [1 2 3 4] ``` -### func [Concat]() +### func [Concat]() ```go func Concat[V any](seqs ...Seq[V]) Seq[V] @@ -897,7 +897,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -919,7 +919,7 @@ func main() { -### func [Cycle]() +### func [Cycle]() ```go func Cycle[T any](seq Seq[T]) Seq[T] @@ -935,7 +935,7 @@ seq := xiter.Cycle(xiter.FromSlice([]int{1, 2, 3})) ``` -### func [Filter]() +### func [Filter]() ```go func Filter[V any](f func(V) bool, seq Seq[V]) Seq[V] @@ -962,7 +962,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -982,7 +982,7 @@ func main() { -### func [FromChan]() +### func [FromChan]() ```go func FromChan[T any](in <-chan T) Seq[T] @@ -1005,7 +1005,7 @@ _ = ToSlice(seq) // Returns []int{1, 2} ``` -### func [FromMapKeys]() +### func [FromMapKeys]() ```go func FromMapKeys[K comparable, V any](m map[K]V) Seq[K] @@ -1014,7 +1014,7 @@ func FromMapKeys[K comparable, V any](m map[K]V) Seq[K] -### func [FromMapValues]() +### func [FromMapValues]() ```go func FromMapValues[K comparable, V any](m map[K]V) Seq[V] @@ -1023,7 +1023,7 @@ func FromMapValues[K comparable, V any](m map[K]V) Seq[V] -### func [FromSlice]() +### func [FromSlice]() ```go func FromSlice[T any](in []T) Seq[T] @@ -1032,7 +1032,7 @@ func FromSlice[T any](in []T) Seq[T] FromSlice received a slice and returned a Seq for this slice. -### func [FromSliceReverse]() +### func [FromSliceReverse]() ```go func FromSliceReverse[T any, Slice ~[]T](in Slice) Seq[T] @@ -1041,7 +1041,7 @@ func FromSliceReverse[T any, Slice ~[]T](in Slice) Seq[T] -### func [FromSliceShuffle]() +### func [FromSliceShuffle]() ```go func FromSliceShuffle[T any](in []T) Seq[T] @@ -1058,7 +1058,7 @@ shuffledSeq := FromSliceShuffle(ToSlice(seq)) ``` -### func [Generate]() +### func [Generate]() ```go func Generate[T any](fn func() T) Seq[T] @@ -1075,7 +1075,7 @@ first5 := xiter.ToSlice(xiter.Limit(seq, 5)) ``` -### func [Intersect]() +### func [Intersect]() ```go func Intersect[T comparable](left Seq[T], right Seq[T]) Seq[T] @@ -1093,7 +1093,7 @@ intersect := Intersect(FromSlice(left), FromSlice(right)) ``` -### func [Limit]() +### func [Limit]() ```go func Limit[V any](seq Seq[V], n int) Seq[V] @@ -1122,7 +1122,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -1142,7 +1142,7 @@ func main() { -### func [Map]() +### func [Map]() ```go func Map[In, Out any](f func(In) Out, seq Seq[In]) Seq[Out] @@ -1171,7 +1171,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -1191,7 +1191,7 @@ func main() { -### func [Merge]() +### func [Merge]() ```go func Merge[V xcmp.Ordered](x, y Seq[V]) Seq[V] @@ -1212,7 +1212,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -1233,7 +1233,7 @@ func main() { -### func [MergeFunc]() +### func [MergeFunc]() ```go func MergeFunc[V any](x, y Seq[V], f func(V, V) int) Seq[V] @@ -1242,7 +1242,7 @@ func MergeFunc[V any](x, y Seq[V], f func(V, V) int) Seq[V] MergeFunc merges two sequences of values ordered by the function f. Values appear in the output once for each time they appear in x and once for each time they appear in y. When equal values appear in both sequences, the output contains the values from x before the values from y. If the two input sequences are not ordered by f, the output sequence will not be ordered by f, but it will still contain every value from x and y exactly once. -### func [Range]() +### func [Range]() ```go func Range[T constraints.Integer](start, end, step T) Seq[T] @@ -1261,7 +1261,7 @@ seq = xiter.Range(10, 0, -3) ``` -### func [Repeat]() +### func [Repeat]() ```go func Repeat[T any](seq Seq[T], count int) Seq[T] @@ -1270,7 +1270,7 @@ func Repeat[T any](seq Seq[T], count int) Seq[T] Repeat return a seq that repeat seq for count times. -### func [Replace]() +### func [Replace]() ```go func Replace[T comparable](seq Seq[T], from, to T, n int) Seq[T] @@ -1287,7 +1287,7 @@ replacedSeq := Replace(seq, 2, 99, -1) // Replace all 2s with 99 ``` -### func [ReplaceAll]() +### func [ReplaceAll]() ```go func ReplaceAll[T comparable](seq Seq[T], from, to T) Seq[T] @@ -1304,7 +1304,7 @@ replacedSeq := ReplaceAll(seq, 2, 99) ``` -### func [Reverse]() +### func [Reverse]() ```go func Reverse[T any](seq Seq[T]) Seq[T] @@ -1313,7 +1313,7 @@ func Reverse[T any](seq Seq[T]) Seq[T] Reverse return a reversed seq. -### func [Seq2KeyToSeq]() +### func [Seq2KeyToSeq]() ```go func Seq2KeyToSeq[K, V any](in Seq2[K, V]) Seq[K] @@ -1322,7 +1322,7 @@ func Seq2KeyToSeq[K, V any](in Seq2[K, V]) Seq[K] Seq2KeyToSeq return a seq that only contain keys in seq2. -### func [Seq2ToSeqUnion]() +### func [Seq2ToSeqUnion]() ```go func Seq2ToSeqUnion[K, V any](seq Seq2[K, V]) Seq[union.U2[K, V]] @@ -1340,7 +1340,7 @@ for v := range Seq2ToSeqUnion(seq2) { ``` -### func [Seq2ValueToSeq]() +### func [Seq2ValueToSeq]() ```go func Seq2ValueToSeq[K, V any](in Seq2[K, V]) Seq[V] @@ -1349,7 +1349,7 @@ func Seq2ValueToSeq[K, V any](in Seq2[K, V]) Seq[V] Seq2ValueToSeq return a seq that only contain values in seq2. -### func [Skip]() +### func [Skip]() ```go func Skip[T any](seq Seq[T], n int) Seq[T] @@ -1358,7 +1358,7 @@ func Skip[T any](seq Seq[T], n int) Seq[T] Skip return a seq that skip n elements from seq. -### func [Union]() +### func [Union]() ```go func Union[T comparable](left, right Seq[T]) Seq[T] @@ -1376,7 +1376,7 @@ union := Union(FromSlice(left), FromSlice(right)) ``` -### func [Uniq]() +### func [Uniq]() ```go func Uniq[T comparable](seq Seq[T]) Seq[T] @@ -1393,7 +1393,7 @@ uniqSeq := xiter.Uniq(seq) ``` -### func [Zip]() +### func [Zip]() ```go func Zip[V1, V2 any](x Seq[V1], y Seq[V2]) Seq[Zipped[V1, V2]] @@ -1425,7 +1425,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func main() { @@ -1451,7 +1451,7 @@ func main() { -### func [Zip2]() +### func [Zip2]() ```go func Zip2[K1, V1, K2, V2 any](x Seq2[K1, V1], y Seq2[K2, V2]) Seq[Zipped2[K1, V1, K2, V2]] @@ -1473,7 +1473,7 @@ func Equal2[K, V comparable](x, y Seq2[K, V]) bool { ``` -## type [Seq2]() +## type [Seq2]() Seq2 is a sequence of key/value pair provided by an iterator\-like function. We made this alias Seq2 to iter.Seq2 for providing a compatible interface in lower go versions. @@ -1482,7 +1482,7 @@ type Seq2[K, V any] iter.Seq2[K, V] ``` -### func [Concat2]() +### func [Concat2]() ```go func Concat2[K, V any](seqs ...Seq2[K, V]) Seq2[K, V] @@ -1491,7 +1491,7 @@ func Concat2[K, V any](seqs ...Seq2[K, V]) Seq2[K, V] Concat2 returns an Seq2 over the concatenation of the given Seq2s. Like Concat but run with Seq2 -### func [Filter2]() +### func [Filter2]() ```go func Filter2[K, V any](f func(K, V) bool, seq Seq2[K, V]) Seq2[K, V] @@ -1500,7 +1500,7 @@ func Filter2[K, V any](f func(K, V) bool, seq Seq2[K, V]) Seq2[K, V] Filter2 returns an Seq over seq that only includes the key\-value pairs k, v for which f\(k, v\) is true. Like Filter but run with Seq2 -### func [FromMapKeyAndValues]() +### func [FromMapKeyAndValues]() ```go func FromMapKeyAndValues[K comparable, V any](m map[K]V) Seq2[K, V] @@ -1509,7 +1509,7 @@ func FromMapKeyAndValues[K comparable, V any](m map[K]V) Seq2[K, V] -### func [FromSliceIdx]() +### func [FromSliceIdx]() ```go func FromSliceIdx[T any](in []T) Seq2[int, T] @@ -1518,7 +1518,7 @@ func FromSliceIdx[T any](in []T) Seq2[int, T] FromSliceIdx received a slice and returned a Seq2 for this slice, key is index. -### func [Limit2]() +### func [Limit2]() ```go func Limit2[K, V any](seq Seq2[K, V], n int) Seq2[K, V] @@ -1527,7 +1527,7 @@ func Limit2[K, V any](seq Seq2[K, V], n int) Seq2[K, V] Limit2 returns a Seq over Seq2 that stops after n key\-value pairs. Like Limit but run with Seq2 -### func [Map2]() +### func [Map2]() ```go func Map2[KIn, VIn, KOut, VOut any](f func(KIn, VIn) (KOut, VOut), seq Seq2[KIn, VIn]) Seq2[KOut, VOut] @@ -1536,7 +1536,7 @@ func Map2[KIn, VIn, KOut, VOut any](f func(KIn, VIn) (KOut, VOut), seq Seq2[KIn, Map2 returns a Seq2 over the results of applying f to each key\-value pair in seq. Like Map but run with Seq2 -### func [MapToSeq2]() +### func [MapToSeq2]() ```go func MapToSeq2[T any, K comparable](in Seq[T], mapFn func(ele T) K) Seq2[K, T] @@ -1557,7 +1557,7 @@ fmt.Println(ToMap(lenMap)) ``` -### func [MapToSeq2Value]() +### func [MapToSeq2Value]() ```go func MapToSeq2Value[T any, K comparable, V any](in Seq[T], mapFn func(ele T) (K, V)) Seq2[K, V] @@ -1577,7 +1577,7 @@ fmt.Println(ToMap(transformed)) ``` -### func [Merge2]() +### func [Merge2]() ```go func Merge2[K xcmp.Ordered, V any](x, y Seq2[K, V]) Seq2[K, V] @@ -1588,7 +1588,7 @@ Merge2 merges two sequences of key\-value pairs ordered by their keys. Pairs app Merge2 is equivalent to calling MergeFunc2 with cmp.Compare\[K\] as the ordering function. -### func [MergeFunc2]() +### func [MergeFunc2]() ```go func MergeFunc2[K, V any](x, y Seq2[K, V], f func(K, K) int) Seq2[K, V] @@ -1597,7 +1597,7 @@ func MergeFunc2[K, V any](x, y Seq2[K, V], f func(K, K) int) Seq2[K, V] MergeFunc2 merges two sequences of key\-value pairs ordered by the function f. Pairs appear in the output once for each time they appear in x and once for each time they appear in y. When pairs with equal keys appear in both sequences, the output contains the pairs from x before the pairs from y. If the two input sequences are not ordered by f, the output sequence will not be ordered by f, but it will still contain every pair from x and y exactly once. -### func [WithIndex]() +### func [WithIndex]() ```go func WithIndex[T any](seq Seq[T]) Seq2[int, T] @@ -1619,7 +1619,7 @@ for idx, v := range xiter.WithIndex(seq) { ``` -## type [Zipped]() +## type [Zipped]() A Zipped is a pair of zipped values, one of which may be missing, drawn from two different sequences. @@ -1633,7 +1633,7 @@ type Zipped[V1, V2 any] struct { ``` -## type [Zipped2]() +## type [Zipped2]() A Zipped2 is a pair of zipped key\-value pairs, one of which may be missing, drawn from two different sequences. diff --git a/pkg/xiter/doc.go b/xiter/doc.go similarity index 100% rename from pkg/xiter/doc.go rename to xiter/doc.go diff --git a/pkg/xiter/xiter.go b/xiter/xiter.go similarity index 99% rename from pkg/xiter/xiter.go rename to xiter/xiter.go index bf1f654..c0ad3b1 100644 --- a/pkg/xiter/xiter.go +++ b/xiter/xiter.go @@ -9,11 +9,11 @@ import ( "math/rand" "strings" - "github.com/dashjay/xiter/pkg/internal/constraints" - "github.com/dashjay/xiter/pkg/internal/utils" - "github.com/dashjay/xiter/pkg/optional" - "github.com/dashjay/xiter/pkg/union" - "github.com/dashjay/xiter/pkg/xcmp" + "github.com/dashjay/xiter/internal/constraints" + "github.com/dashjay/xiter/internal/utils" + "github.com/dashjay/xiter/optional" + "github.com/dashjay/xiter/union" + "github.com/dashjay/xiter/xcmp" ) // Seq is a sequence of elements provided by an iterator-like function. diff --git a/pkg/xiter/xiter_benchmark_test.go b/xiter/xiter_benchmark_test.go similarity index 96% rename from pkg/xiter/xiter_benchmark_test.go rename to xiter/xiter_benchmark_test.go index 5e080bd..498d288 100644 --- a/pkg/xiter/xiter_benchmark_test.go +++ b/xiter/xiter_benchmark_test.go @@ -3,7 +3,7 @@ package xiter_test import ( "testing" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" ) func BenchmarkCycle(b *testing.B) { diff --git a/pkg/xiter/xiter_common.go b/xiter/xiter_common.go similarity index 98% rename from pkg/xiter/xiter_common.go rename to xiter/xiter_common.go index 014b017..dddc05e 100644 --- a/pkg/xiter/xiter_common.go +++ b/xiter/xiter_common.go @@ -1,9 +1,9 @@ package xiter import ( - "github.com/dashjay/xiter/pkg/internal/constraints" - gassert "github.com/dashjay/xiter/pkg/internal/xassert" - "github.com/dashjay/xiter/pkg/optional" + "github.com/dashjay/xiter/internal/constraints" + gassert "github.com/dashjay/xiter/internal/xassert" + "github.com/dashjay/xiter/optional" ) // A Zipped2 is a pair of zipped key-value pairs, diff --git a/pkg/xiter/xiter_common_test.go b/xiter/xiter_common_test.go similarity index 99% rename from pkg/xiter/xiter_common_test.go rename to xiter/xiter_common_test.go index df2ece4..82b50b2 100644 --- a/pkg/xiter/xiter_common_test.go +++ b/xiter/xiter_common_test.go @@ -5,7 +5,7 @@ import ( "strconv" "testing" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" "github.com/stretchr/testify/assert" ) diff --git a/pkg/xiter/xiter_old.go b/xiter/xiter_old.go similarity index 98% rename from pkg/xiter/xiter_old.go rename to xiter/xiter_old.go index 32ba966..88e5102 100644 --- a/pkg/xiter/xiter_old.go +++ b/xiter/xiter_old.go @@ -9,11 +9,11 @@ import ( "strconv" "strings" - "github.com/dashjay/xiter/pkg/internal/constraints" - "github.com/dashjay/xiter/pkg/internal/utils" - "github.com/dashjay/xiter/pkg/optional" - "github.com/dashjay/xiter/pkg/union" - "github.com/dashjay/xiter/pkg/xcmp" + "github.com/dashjay/xiter/internal/constraints" + "github.com/dashjay/xiter/internal/utils" + "github.com/dashjay/xiter/optional" + "github.com/dashjay/xiter/union" + "github.com/dashjay/xiter/xcmp" ) type Seq[V any] func(yield func(V) bool) diff --git a/pkg/xiter/xiter_pull_test.go b/xiter/xiter_pull_test.go similarity index 99% rename from pkg/xiter/xiter_pull_test.go rename to xiter/xiter_pull_test.go index c6990bf..2e51910 100644 --- a/pkg/xiter/xiter_pull_test.go +++ b/xiter/xiter_pull_test.go @@ -6,7 +6,7 @@ package xiter_test import ( "fmt" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/xiter" "github.com/stretchr/testify/assert" "runtime" "testing" diff --git a/pkg/xiter/xiter_test.go b/xiter/xiter_test.go similarity index 99% rename from pkg/xiter/xiter_test.go rename to xiter/xiter_test.go index 63c4cec..259bf08 100644 --- a/pkg/xiter/xiter_test.go +++ b/xiter/xiter_test.go @@ -7,9 +7,9 @@ import ( "strconv" "testing" - "github.com/dashjay/xiter/pkg/internal/constraints" - "github.com/dashjay/xiter/pkg/optional" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/internal/constraints" + "github.com/dashjay/xiter/optional" + "github.com/dashjay/xiter/xiter" "github.com/stretchr/testify/assert" ) diff --git a/pkg/xmap/README.md b/xmap/README.md similarity index 89% rename from pkg/xmap/README.md rename to xmap/README.md index fce8245..e1eeeec 100644 --- a/pkg/xmap/README.md +++ b/xmap/README.md @@ -3,7 +3,7 @@ # xmap ```go -import "github.com/dashjay/xiter/pkg/xmap" +import "github.com/dashjay/xiter/xmap" ``` ## Index @@ -35,7 +35,7 @@ import "github.com/dashjay/xiter/pkg/xmap" -## func [Clone]() +## func [Clone]() ```go func Clone[M ~map[K]V, K comparable, V any](m M) M @@ -44,7 +44,7 @@ func Clone[M ~map[K]V, K comparable, V any](m M) M -## func [CoalesceMaps]() +## func [CoalesceMaps]() ```go func CoalesceMaps[M ~map[K]V, K comparable, V any](maps ...M) M @@ -79,7 +79,7 @@ result := CoalesceMaps(map1, map2, map3) ``` -## func [Copy]() +## func [Copy]() ```go func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2) @@ -88,7 +88,7 @@ func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2) -## func [Delete]() +## func [Delete]() ```go func Delete[K comparable, V any](m map[K]V, k K) (old V, deleted bool) @@ -107,7 +107,7 @@ old, deleted = xmap.Delete(m, "c") ``` -## func [DeleteIf]() +## func [DeleteIf]() ```go func DeleteIf[K comparable, V any](m map[K]V, k K, c func(K, V) bool) (old V, deleted bool) @@ -128,7 +128,7 @@ old, deleted = xmap.DeleteIf(m, "c", func(k string, v int) bool { return v > 0 } ``` -## func [Equal]() +## func [Equal]() ```go func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool @@ -137,7 +137,7 @@ func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool -## func [EqualFunc]() +## func [EqualFunc]() ```go func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool @@ -146,7 +146,7 @@ func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M -## func [Filter]() +## func [Filter]() ```go func Filter[M ~map[K]V, K comparable, V any](in M, fn func(K, V) bool) M @@ -164,7 +164,7 @@ result := Filter(m, fn) ``` -## func [Find]() +## func [Find]() ```go func Find[K comparable, V any](in map[K]V, fn func(K, V) bool) (K, V, bool) @@ -183,7 +183,7 @@ key, value, found = xmap.Find(m, func(k string, v int) bool { return v > 10 }) ``` -## func [FindKey]() +## func [FindKey]() ```go func FindKey[K comparable, V any](in map[K]V, target K) (K, V, bool) @@ -202,7 +202,7 @@ key, value, found = xmap.FindKey(m, "c") ``` -## func [FindKeyO]() +## func [FindKeyO]() ```go func FindKeyO[K comparable, V any](in map[K]V, target K) optional.O[union.U2[K, V]] @@ -223,7 +223,7 @@ result2 := xmap.FindKeyO(m, "c") ``` -## func [FindO]() +## func [FindO]() ```go func FindO[K comparable, V any](in map[K]V, fn func(K, V) bool) optional.O[union.U2[K, V]] @@ -244,7 +244,7 @@ result2 := xmap.FindO(m, func(k string, v int) bool { return v > 10 }) ``` -## func [Keys]() +## func [Keys]() ```go func Keys[M ~map[K]V, K comparable, V any](m M) []K @@ -253,7 +253,7 @@ func Keys[M ~map[K]V, K comparable, V any](m M) []K -## func [MapKeys]() +## func [MapKeys]() ```go func MapKeys[K comparable, V1 any](in map[K]V1, fn func(K, V1) K) map[K]V1 @@ -286,7 +286,7 @@ result := MapKeys(m, fn) ``` -## func [MapValues]() +## func [MapValues]() ```go func MapValues[K comparable, V1, V2 any](in map[K]V1, fn func(K, V1) V2) map[K]V2 @@ -319,7 +319,7 @@ result := MapValues(m, fn) ``` -## func [MaxKey]() +## func [MaxKey]() ```go func MaxKey[K constraints.Ordered, V any](m map[K]V) optional.O[union.U2[K, V]] @@ -340,7 +340,7 @@ result2 := xmap.MaxKey(map[string]int{}) ``` -## func [MaxValue]() +## func [MaxValue]() ```go func MaxValue[K comparable, V constraints.Ordered](m map[K]V) optional.O[union.U2[K, V]] @@ -361,7 +361,7 @@ result2 := xmap.MaxValue(map[string]int{}) ``` -## func [MinKey]() +## func [MinKey]() ```go func MinKey[K constraints.Ordered, V any](m map[K]V) optional.O[union.U2[K, V]] @@ -382,7 +382,7 @@ result2 := xmap.MinKey(map[string]int{}) ``` -## func [MinValue]() +## func [MinValue]() ```go func MinValue[K comparable, V constraints.Ordered](m map[K]V) optional.O[union.U2[K, V]] @@ -403,7 +403,7 @@ result2 := xmap.MinValue(map[string]int{}) ``` -## func [ToUnionSlice]() +## func [ToUnionSlice]() ```go func ToUnionSlice[M ~map[K]V, K comparable, V any](m M) []union.U2[K, V] @@ -412,7 +412,7 @@ func ToUnionSlice[M ~map[K]V, K comparable, V any](m M) []union.U2[K, V] -## func [ToXSyncMap]() +## func [ToXSyncMap]() ```go func ToXSyncMap[K comparable, V any](in map[K]V) *xsync.SyncMap[K, V] @@ -433,7 +433,7 @@ Returns: ``` -## func [Update]() +## func [Update]() ```go func Update[K comparable, V any](m map[K]V, k K, v V) (old V, replaced bool) @@ -452,7 +452,7 @@ old, replaced = xmap.Update(m, "c", 3) ``` -## func [UpdateIf]() +## func [UpdateIf]() ```go func UpdateIf[K comparable, V any](m map[K]V, k K, v V, c func(K, V) bool) (old V, replaced bool) @@ -473,7 +473,7 @@ old, replaced = xmap.UpdateIf(m, "c", 3, func(k string, v int) bool { return v > ``` -## func [Values]() +## func [Values]() ```go func Values[M ~map[K]V, K comparable, V any](m M) []V diff --git a/pkg/xmap/xmap.go b/xmap/xmap.go similarity index 96% rename from pkg/xmap/xmap.go rename to xmap/xmap.go index 99120e7..0725973 100644 --- a/pkg/xmap/xmap.go +++ b/xmap/xmap.go @@ -6,7 +6,7 @@ package xmap import ( "maps" - "github.com/dashjay/xiter/pkg/union" + "github.com/dashjay/xiter/union" ) func Clone[M ~map[K]V, K comparable, V any](m M) M { diff --git a/pkg/xmap/xmap_benchmark_test.go b/xmap/xmap_benchmark_test.go similarity index 97% rename from pkg/xmap/xmap_benchmark_test.go rename to xmap/xmap_benchmark_test.go index f0e27cc..c022111 100644 --- a/pkg/xmap/xmap_benchmark_test.go +++ b/xmap/xmap_benchmark_test.go @@ -3,7 +3,7 @@ package xmap_test import ( "testing" - "github.com/dashjay/xiter/pkg/xmap" + "github.com/dashjay/xiter/xmap" ) var _ = _map // suppress unused lint diff --git a/pkg/xmap/xmap_common.go b/xmap/xmap_common.go similarity index 98% rename from pkg/xmap/xmap_common.go rename to xmap/xmap_common.go index 48e2b8e..3b382a3 100644 --- a/pkg/xmap/xmap_common.go +++ b/xmap/xmap_common.go @@ -1,10 +1,10 @@ package xmap import ( - "github.com/dashjay/xiter/pkg/internal/constraints" - "github.com/dashjay/xiter/pkg/optional" - "github.com/dashjay/xiter/pkg/union" - "github.com/dashjay/xiter/pkg/xsync" + "github.com/dashjay/xiter/internal/constraints" + "github.com/dashjay/xiter/optional" + "github.com/dashjay/xiter/union" + "github.com/dashjay/xiter/xsync" ) // CoalesceMaps combines multiple maps into a single map. When duplicate keys are encountered, diff --git a/pkg/xmap/xmap_old.go b/xmap/xmap_old.go similarity index 97% rename from pkg/xmap/xmap_old.go rename to xmap/xmap_old.go index a521494..01a4f24 100644 --- a/pkg/xmap/xmap_old.go +++ b/xmap/xmap_old.go @@ -4,7 +4,7 @@ package xmap import ( - "github.com/dashjay/xiter/pkg/union" + "github.com/dashjay/xiter/union" ) func Clone[M ~map[K]V, K comparable, V any](m M) M { diff --git a/pkg/xmap/xmap_test.go b/xmap/xmap_test.go similarity index 99% rename from pkg/xmap/xmap_test.go rename to xmap/xmap_test.go index de8bd57..da98cbd 100644 --- a/pkg/xmap/xmap_test.go +++ b/xmap/xmap_test.go @@ -5,9 +5,9 @@ import ( "sort" "testing" - "github.com/dashjay/xiter/pkg/union" - "github.com/dashjay/xiter/pkg/xiter" - "github.com/dashjay/xiter/pkg/xmap" + "github.com/dashjay/xiter/union" + "github.com/dashjay/xiter/xiter" + "github.com/dashjay/xiter/xmap" "github.com/stretchr/testify/assert" ) diff --git a/pkg/xslice/README.md b/xslice/README.md similarity index 84% rename from pkg/xslice/README.md rename to xslice/README.md index e97da29..6aa7570 100644 --- a/pkg/xslice/README.md +++ b/xslice/README.md @@ -3,7 +3,7 @@ # xslice ```go -import "github.com/dashjay/xiter/pkg/xslice" +import "github.com/dashjay/xiter/xslice" ``` ## Index @@ -79,7 +79,7 @@ import "github.com/dashjay/xiter/pkg/xslice" -## func [All]() +## func [All]() ```go func All[T any](in []T, f func(T) bool) bool @@ -95,7 +95,7 @@ xslice.All([]int{-1, 1, 2, 3}, func(x int) bool { return x > 0 }) πŸ‘‰ false ``` -## func [AllEqual]() +## func [AllEqual]() ```go func AllEqual[T comparable](in []T) bool @@ -111,7 +111,7 @@ xslice.AllEqual([]int{1, 2, 1, 1}) πŸ‘‰ false ``` -## func [Any]() +## func [Any]() ```go func Any[T any](in []T, f func(T) bool) bool @@ -127,7 +127,7 @@ xslice.Any([]int{0, 1, 2, 3}, func(x int) bool { return x == -1 }) πŸ‘‰ false ``` -## func [Avg]() +## func [Avg]() ```go func Avg[T constraints.Number](in []T) float64 @@ -143,7 +143,7 @@ xslice.Avg([]int{}) πŸ‘‰ float(0) ``` -## func [AvgBy]() +## func [AvgBy]() ```go func AvgBy[V any, T constraints.Number](in []V, f func(V) T) float64 @@ -161,7 +161,7 @@ xslice.AvgBy([]string{"1", "2", "3"}, func(x string) int { ``` -## func [AvgN]() +## func [AvgN]() ```go func AvgN[T constraints.Number](inputs ...T) float64 @@ -177,7 +177,7 @@ xslice.AvgN() πŸ‘‰ float(0) ``` -## func [Chunk]() +## func [Chunk]() ```go func Chunk[T any, Slice ~[]T](in Slice, chunkSize int) []Slice @@ -194,7 +194,7 @@ xslice.Chunk([]int{1, 2, 3, 4, 5}, 0) πŸ‘‰ []int{} ``` -## func [ChunkInPlace]() +## func [ChunkInPlace]() ```go func ChunkInPlace[T any, Slice ~[]T](in Slice, chunkSize int) []Slice @@ -209,7 +209,7 @@ xslice.Chunk([]int{1, 2, 3, 4, 5}, 0) πŸ‘‰ []int{} ``` -## func [Clone]() +## func [Clone]() ```go func Clone[T any](in []T) []T @@ -224,7 +224,7 @@ xslice.Clone([]int{1, 2, 3}) πŸ‘‰ [1, 2, 3] ``` -## func [CloneBy]() +## func [CloneBy]() ```go func CloneBy[T any, U any](in []T, f func(T) U) []U @@ -240,7 +240,7 @@ xslice.CloneBy([]int{1, 2, 3}, strconv.Itoa) πŸ‘‰ ["1", "2", "3"] ``` -## func [Compact]() +## func [Compact]() ```go func Compact[T comparable, Slice ~[]T](in Slice) Slice @@ -255,7 +255,7 @@ xslice.Compact([]int{0, 1, 2, 3, 4}) πŸ‘‰ [1 2 3 4] ``` -## func [Concat]() +## func [Concat]() ```go func Concat[T any](vs ...[]T) []T @@ -271,7 +271,7 @@ xslice.Concat([]int{1, 2, 3}, []int{}) πŸ‘‰ [1, 2, 3] ``` -## func [Contains]() +## func [Contains]() ```go func Contains[T comparable](in []T, v T) bool @@ -287,7 +287,7 @@ xslice.Contains([]int{-1, 2, 3}, 1) πŸ‘‰ false ``` -## func [ContainsAll]() +## func [ContainsAll]() ```go func ContainsAll[T comparable](in []T, v []T) bool @@ -304,7 +304,7 @@ xslice.ContainsAll([]string{"1", "2", "3"}, []string{}) πŸ‘‰ true ``` -## func [ContainsAny]() +## func [ContainsAny]() ```go func ContainsAny[T comparable](in []T, v []T) bool @@ -321,7 +321,7 @@ xslice.ContainsAny([]string{"1", "2", "3"}, []string{}) πŸ‘‰ false ``` -## func [ContainsBy]() +## func [ContainsBy]() ```go func ContainsBy[T any](in []T, f func(T) bool) bool @@ -344,7 +344,7 @@ xslice.ContainsBy([]string{"1", "2", "3"}, func(x string) bool { ``` -## func [Count]() +## func [Count]() ```go func Count[T any](in []T) int @@ -360,7 +360,7 @@ xslice.Count([]int{}) πŸ‘‰ 0 ``` -## func [CountBy]() +## func [CountBy]() ```go func CountBy[T any, K comparable](in []T, fn func(T) K) map[K]int @@ -376,7 +376,7 @@ xslice.CountBy([]int{1, 2, 3, 2, 1, 2}, func(x int) int { return x }) ``` -## func [Difference]() +## func [Difference]() ```go func Difference[T comparable, Slice ~[]T](left, right Slice) (onlyLeft, onlyRight Slice) @@ -395,7 +395,7 @@ fmt.Println(onlyRight) // [6 7 8] ``` -## func [Filter]() +## func [Filter]() ```go func Filter[T any, Slice ~[]T](in Slice, f func(T) bool) Slice @@ -410,7 +410,7 @@ xslice.Filter([]int{1, 2, 3, 2, 4}, func(x int) bool { return x%2 == 0 }) πŸ‘‰ [ ``` -## func [Find]() +## func [Find]() ```go func Find[T any](in []T, f func(T) bool) (val T, found bool) @@ -426,7 +426,7 @@ xslice.Find([]int{1, 2, 3}, func(x int) bool { return x == -1 }) πŸ‘‰ 0, false ``` -## func [FindO]() +## func [FindO]() ```go func FindO[T any](in []T, f func(T) bool) optional.O[T] @@ -442,7 +442,7 @@ xslice.FindO(_range(0, 10), func(x int) bool { return x == -1 }).Ok() πŸ‘‰ false ``` -## func [First]() +## func [First]() ```go func First[T any, Slice ~[]T](in Slice) (T, bool) @@ -456,7 +456,7 @@ xslice.First([]int{}) πŸ‘‰ 0 ``` -## func [FirstO]() +## func [FirstO]() ```go func FirstO[T any, Slice ~[]T](in Slice) optional.O[T] @@ -470,7 +470,7 @@ xslice.FirstO([]int{}) πŸ‘‰ 0 ``` -## func [FlatMap]() +## func [FlatMap]() ```go func FlatMap[T any, U any](in []T, fn func(T) []U) []U @@ -486,7 +486,7 @@ xslice.FlatMap([]int{1, 2, 3}, func(x int) []int { return []int{x, x * 10} }) ``` -## func [Flatten]() +## func [Flatten]() ```go func Flatten[T any](in [][]T) []T @@ -504,7 +504,7 @@ xslice.Flatten([][]int{{}, {}, {}}) πŸ‘‰ []int{} ``` -## func [ForEach]() +## func [ForEach]() ```go func ForEach[T any](in []T, f func(T) bool) @@ -526,7 +526,7 @@ Output: ``` -## func [ForEachIdx]() +## func [ForEachIdx]() ```go func ForEachIdx[T any](in []T, f func(idx int, v T) bool) @@ -548,7 +548,7 @@ Output: ``` -## func [GroupBy]() +## func [GroupBy]() ```go func GroupBy[T any, K comparable, Slice ~[]T](in Slice, f func(T) K) map[K]Slice @@ -563,7 +563,7 @@ xslice.GroupBy([]int{1, 2, 3, 2, 4}, func(x int) int { return x % 2 }) πŸ‘‰ map[ ``` -## func [GroupByMap]() +## func [GroupByMap]() ```go func GroupByMap[T any, Slice ~[]T, K comparable, V any](in Slice, f func(T) (K, V)) map[K][]V @@ -578,7 +578,7 @@ xslice.GroupByMap([]int{1, 2, 3, 2, 4}, func(x int) (int, int) { return x % 2, x ``` -## func [Head]() +## func [Head]() ```go func Head[T any](in []T) (v T, hasOne bool) @@ -594,7 +594,7 @@ optional.FromValue2(xslice.Head(_range(0, 0))).Ok() πŸ‘‰ false ``` -## func [HeadO]() +## func [HeadO]() ```go func HeadO[T any](in []T) optional.O[T] @@ -610,7 +610,7 @@ xslice.HeadO(_range(0, 0)).Ok() πŸ‘‰ false ``` -## func [Index]() +## func [Index]() ```go func Index[T comparable, Slice ~[]T](in Slice, v T) int @@ -625,7 +625,7 @@ xslice.Index([]int{1, 2, 3, 4, 5}, 666) πŸ‘‰ -1 ``` -## func [Intersect]() +## func [Intersect]() ```go func Intersect[T comparable, Slice ~[]T](left, right Slice) Slice @@ -643,7 +643,7 @@ fmt.Println(intersect) // [4 5] ``` -## func [IsSorted]() +## func [IsSorted]() ```go func IsSorted[T constraints.Ordered](in []T) bool @@ -659,7 +659,7 @@ xslice.IsSorted([]int{1, 3, 2, 4}) πŸ‘‰ false ``` -## func [Join]() +## func [Join]() ```go func Join[T ~string](in []T, sep T) T @@ -675,7 +675,7 @@ xslice.Join([]string{}, ".") πŸ‘‰ "" ``` -## func [KeyBy]() +## func [KeyBy]() ```go func KeyBy[T any, K comparable](in []T, fn func(T) K) map[K]T @@ -691,7 +691,7 @@ xslice.KeyBy([]int{1, 2, 3}, func(x int) int { return x * 10 }) ``` -## func [Last]() +## func [Last]() ```go func Last[T any, Slice ~[]T](in Slice) (T, bool) @@ -705,7 +705,7 @@ xslice.Last([]int{}) πŸ‘‰ 0 ``` -## func [LastO]() +## func [LastO]() ```go func LastO[T any, Slice ~[]T](in Slice) optional.O[T] @@ -719,7 +719,7 @@ xslice.LastO([]int{}) πŸ‘‰ 0 ``` -## func [Map]() +## func [Map]() ```go func Map[T any, U any](in []T, f func(T) U) []U @@ -735,7 +735,7 @@ xslice.Map([]int{1, 2, 3}, strconv.Itoa) πŸ‘‰ ["1", "2", "3"] ``` -## func [Max]() +## func [Max]() ```go func Max[T constraints.Ordered](in []T) optional.O[T] @@ -751,7 +751,7 @@ xslice.Max([]int{}) πŸ‘‰ 0 ``` -## func [MaxBy]() +## func [MaxBy]() ```go func MaxBy[T constraints.Ordered](in []T, f func(T, T) bool) optional.O[T] @@ -766,7 +766,7 @@ xslice.MaxBy([]int{1, 2, 3} /*less = */, func(a, b int) bool { return a > b }).M ``` -## func [MaxN]() +## func [MaxN]() ```go func MaxN[T constraints.Ordered](in ...T) optional.O[T] @@ -781,7 +781,7 @@ xslice.MaxN(1, 2, 3) πŸ‘‰ 3 ``` -## func [Min]() +## func [Min]() ```go func Min[T constraints.Ordered](in []T) optional.O[T] @@ -797,7 +797,7 @@ xslice.Min([]int{}) πŸ‘‰ 0 ``` -## func [MinBy]() +## func [MinBy]() ```go func MinBy[T constraints.Ordered](in []T, f func(T, T) bool) optional.O[T] @@ -812,7 +812,7 @@ xslice.MinBy([]int{3, 2, 1} /*less = */, func(a, b int) bool { return a > b }).M ``` -## func [MinMax]() +## func [MinMax]() ```go func MinMax[T constraints.Ordered](in []T) (min T, max T, ok bool) @@ -828,7 +828,7 @@ xslice.MinMax([]int{}) πŸ‘‰ (0, 0, false) ``` -## func [MinN]() +## func [MinN]() ```go func MinN[T constraints.Ordered](in ...T) optional.O[T] @@ -843,7 +843,7 @@ xslice.MinN(1, 2, 3) πŸ‘‰ 1 ``` -## func [Mode]() +## func [Mode]() ```go func Mode[T comparable](in []T) optional.O[T] @@ -859,7 +859,7 @@ xslice.Mode([]int{}) πŸ‘‰ optional.Empty[int]() ``` -## func [Partition]() +## func [Partition]() ```go func Partition[T any, Slice ~[]T](in Slice, fn func(T) bool) (yes, no Slice) @@ -875,7 +875,7 @@ yes, no := xslice.Partition([]int{1, 2, 3, 4, 5}, func(x int) bool { return x%2 ``` -## func [RandomElement]() +## func [RandomElement]() ```go func RandomElement[T any, Slice ~[]T](in Slice) optional.O[T] @@ -892,7 +892,7 @@ xslice.RandomElement([]int{}).Ok() πŸ‘‰ false ``` -## func [Remove]() +## func [Remove]() ```go func Remove[T comparable, Slice ~[]T](in Slice, wantToRemove ...T) Slice @@ -909,7 +909,7 @@ fmt.Println(arr1) // [2, 3, 4] ``` -## func [Repeat]() +## func [Repeat]() ```go func Repeat[T any, Slice ~[]T](in Slice, count int) Slice @@ -925,7 +925,7 @@ xslice.Repeat([]int{1, 2, 3}, 0) πŸ‘‰ []int{} ``` -## func [RepeatBy]() +## func [RepeatBy]() ```go func RepeatBy[T any](n int, f func(i int) T) []T @@ -941,7 +941,7 @@ xslice.RepeatBy(3, func(i int) string { return strconv.Itoa(i) }) πŸ‘‰ []string{ ``` -## func [Replace]() +## func [Replace]() ```go func Replace[T comparable, Slice ~[]T](in Slice, from, to T, count int) []T @@ -957,7 +957,7 @@ xslice.Replace([]int{1, 2, 2}, 2, 4, -1) πŸ‘‰ [1, 4, 4] ``` -## func [ReplaceAll]() +## func [ReplaceAll]() ```go func ReplaceAll[T comparable, Slice ~[]T](in Slice, from, to T) []T @@ -973,7 +973,7 @@ xslice.ReplaceAll([]int{1, 2, 2}, 2, 4) πŸ‘‰ [1, 4, 4] ``` -## func [Reverse]() +## func [Reverse]() ```go func Reverse[T any, Slice ~[]T](in Slice) @@ -989,7 +989,7 @@ xslice.Reverse([]int{}) πŸ‘‰ []int{} ``` -## func [ReverseClone]() +## func [ReverseClone]() ```go func ReverseClone[T any, Slice ~[]T](in Slice) Slice @@ -1006,7 +1006,7 @@ xslice.ReverseClone([]int{3, 2, 1}) πŸ‘‰ [1, 2, 3] ``` -## func [Sample]() +## func [Sample]() ```go func Sample[T any, Slice ~[]T](in Slice, n int) Slice @@ -1024,7 +1024,7 @@ xslice.Sample([]int{}, 3) πŸ‘‰ []int{} ``` -## func [Shuffle]() +## func [Shuffle]() ```go func Shuffle[T any, Slice ~[]T](in Slice) Slice @@ -1040,7 +1040,7 @@ xslice.Shuffle([]int{}) πŸ‘‰ []int{} ``` -## func [ShuffleInPlace]() +## func [ShuffleInPlace]() ```go func ShuffleInPlace[T any, Slice ~[]T](in Slice) @@ -1056,7 +1056,7 @@ xslice.ShuffleInPlace(array) πŸ‘‰ [2, 1, 3] (random) ``` -## func [Subset]() +## func [Subset]() ```go func Subset[T any, Slice ~[]T](in Slice, start, count int) Slice @@ -1072,7 +1072,7 @@ xslice.Subset([]int{1, 2, 3}, -1, 2) πŸ‘‰ [2, 3] ``` -## func [SubsetInPlace]() +## func [SubsetInPlace]() ```go func SubsetInPlace[T any, Slice ~[]T](in Slice, start int, count int) Slice @@ -1086,7 +1086,7 @@ xslice.SubsetInPlace([]int{1, 2, 3}, -1, 2) πŸ‘‰ [2, 3] ``` -## func [Sum]() +## func [Sum]() ```go func Sum[T constraints.Number, Slice ~[]T](in Slice) T @@ -1102,7 +1102,7 @@ xslice.Sum([]int{}) πŸ‘‰ 0 ``` -## func [SumBy]() +## func [SumBy]() ```go func SumBy[T any, R constraints.Number, Slice ~[]T](in Slice, f func(T) R) R @@ -1121,7 +1121,7 @@ xslice.SumBy([]string{}, func(x string) int { return 0 }) πŸ‘‰ 0 ``` -## func [SumN]() +## func [SumN]() ```go func SumN[T constraints.Number](in ...T) T @@ -1137,7 +1137,7 @@ xslice.SumN() πŸ‘‰ 0 ``` -## func [ToMap]() +## func [ToMap]() ```go func ToMap[T comparable, U any](in []T, f func(T) U) map[T]U @@ -1155,7 +1155,7 @@ xslice.ToMap([]int{}, func(i int) string { return "" }) πŸ‘‰ map[int]string{} ``` -## func [Union]() +## func [Union]() ```go func Union[T comparable, Slice ~[]T](left, right Slice) Slice @@ -1173,7 +1173,7 @@ fmt.Println(union) // [1 2 3 4 5 6] ``` -## func [Uniq]() +## func [Uniq]() ```go func Uniq[T comparable, Slice ~[]T](in Slice) Slice diff --git a/pkg/xslice/doc.go b/xslice/doc.go similarity index 100% rename from pkg/xslice/doc.go rename to xslice/doc.go diff --git a/pkg/xslice/xslice.go b/xslice/xslice.go similarity index 99% rename from pkg/xslice/xslice.go rename to xslice/xslice.go index 1375170..21362a6 100644 --- a/pkg/xslice/xslice.go +++ b/xslice/xslice.go @@ -3,10 +3,10 @@ package xslice import ( "math/rand" - "github.com/dashjay/xiter/pkg/internal/constraints" - "github.com/dashjay/xiter/pkg/internal/xassert" - "github.com/dashjay/xiter/pkg/optional" - "github.com/dashjay/xiter/pkg/xiter" + "github.com/dashjay/xiter/internal/constraints" + "github.com/dashjay/xiter/internal/xassert" + "github.com/dashjay/xiter/optional" + "github.com/dashjay/xiter/xiter" ) // All returns true if all elements in the slice satisfy the condition provided by f. diff --git a/pkg/xslice/xslice_benchmark_test.go b/xslice/xslice_benchmark_test.go similarity index 99% rename from pkg/xslice/xslice_benchmark_test.go rename to xslice/xslice_benchmark_test.go index 676f211..d7dd506 100644 --- a/pkg/xslice/xslice_benchmark_test.go +++ b/xslice/xslice_benchmark_test.go @@ -7,7 +7,7 @@ import ( "github.com/samber/lo" - "github.com/dashjay/xiter/pkg/xslice" + "github.com/dashjay/xiter/xslice" ) func BenchmarkSlice(b *testing.B) { diff --git a/pkg/xslice/xslice_test.go b/xslice/xslice_test.go similarity index 99% rename from pkg/xslice/xslice_test.go rename to xslice/xslice_test.go index 862442d..abd8092 100644 --- a/pkg/xslice/xslice_test.go +++ b/xslice/xslice_test.go @@ -6,10 +6,10 @@ import ( "strconv" "testing" - "github.com/dashjay/xiter/pkg/internal/constraints" - "github.com/dashjay/xiter/pkg/optional" - "github.com/dashjay/xiter/pkg/xiter" - "github.com/dashjay/xiter/pkg/xslice" + "github.com/dashjay/xiter/internal/constraints" + "github.com/dashjay/xiter/optional" + "github.com/dashjay/xiter/xiter" + "github.com/dashjay/xiter/xslice" "github.com/stretchr/testify/assert" ) diff --git a/pkg/xstl/README.md b/xstl/README.md similarity index 86% rename from pkg/xstl/README.md rename to xstl/README.md index b4a944d..cd22610 100644 --- a/pkg/xstl/README.md +++ b/xstl/README.md @@ -3,7 +3,7 @@ # list ```go -import "github.com/dashjay/xiter/pkg/xstl/list" +import "github.com/dashjay/xiter/xstl/list" ``` Package list implements a doubly linked list. The implementation is a direct port with generics of "container/list" from the Go standard library. @@ -27,7 +27,7 @@ package main import ( "fmt" - "github.com/dashjay/xiter/pkg/xstl/list" + "github.com/dashjay/xiter/xstl/list" ) func main() { @@ -83,7 +83,7 @@ func main() { -## type [Element]() +## type [Element]() Element is an element of a linked list. @@ -97,7 +97,7 @@ type Element[V any] struct { ``` -### func \(\*Element\[V\]\) [Next]() +### func \(\*Element\[V\]\) [Next]() ```go func (e *Element[V]) Next() *Element[V] @@ -106,7 +106,7 @@ func (e *Element[V]) Next() *Element[V] Next returns the next list element or nil. -### func \(\*Element\[V\]\) [Prev]() +### func \(\*Element\[V\]\) [Prev]() ```go func (e *Element[V]) Prev() *Element[V] @@ -115,7 +115,7 @@ func (e *Element[V]) Prev() *Element[V] Prev returns the previous list element or nil. -## type [List]() +## type [List]() List represents a doubly linked list. The zero value for List is an empty list ready to use. @@ -126,7 +126,7 @@ type List[V any] struct { ``` -### func [New]() +### func [New]() ```go func New[V any]() *List[V] @@ -135,7 +135,7 @@ func New[V any]() *List[V] New returns an initialized list. -### func \(\*List\[V\]\) [Back]() +### func \(\*List\[V\]\) [Back]() ```go func (l *List[V]) Back() *Element[V] @@ -144,7 +144,7 @@ func (l *List[V]) Back() *Element[V] Back returns the last element of list l or nil if the list is empty. -### func \(\*List\[V\]\) [Front]() +### func \(\*List\[V\]\) [Front]() ```go func (l *List[V]) Front() *Element[V] @@ -153,7 +153,7 @@ func (l *List[V]) Front() *Element[V] Front returns the first element of list l or nil if the list is empty. -### func \(\*List\[V\]\) [Init]() +### func \(\*List\[V\]\) [Init]() ```go func (l *List[V]) Init() *List[V] @@ -162,7 +162,7 @@ func (l *List[V]) Init() *List[V] Init initializes or clears list l. -### func \(\*List\[V\]\) [InsertAfter]() +### func \(\*List\[V\]\) [InsertAfter]() ```go func (l *List[V]) InsertAfter(v V, mark *Element[V]) *Element[V] @@ -171,7 +171,7 @@ func (l *List[V]) InsertAfter(v V, mark *Element[V]) *Element[V] InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil. -### func \(\*List\[V\]\) [InsertBefore]() +### func \(\*List\[V\]\) [InsertBefore]() ```go func (l *List[V]) InsertBefore(v V, mark *Element[V]) *Element[V] @@ -180,7 +180,7 @@ func (l *List[V]) InsertBefore(v V, mark *Element[V]) *Element[V] InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil. -### func \(\*List\[V\]\) [Len]() +### func \(\*List\[V\]\) [Len]() ```go func (l *List[V]) Len() int @@ -189,7 +189,7 @@ func (l *List[V]) Len() int Len returns the number of elements of list l. The complexity is O\(1\). -### func \(\*List\[V\]\) [MoveAfter]() +### func \(\*List\[V\]\) [MoveAfter]() ```go func (l *List[V]) MoveAfter(e, mark *Element[V]) @@ -198,7 +198,7 @@ func (l *List[V]) MoveAfter(e, mark *Element[V]) MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil. -### func \(\*List\[V\]\) [MoveBefore]() +### func \(\*List\[V\]\) [MoveBefore]() ```go func (l *List[V]) MoveBefore(e, mark *Element[V]) @@ -207,7 +207,7 @@ func (l *List[V]) MoveBefore(e, mark *Element[V]) MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil. -### func \(\*List\[V\]\) [MoveToBack]() +### func \(\*List\[V\]\) [MoveToBack]() ```go func (l *List[V]) MoveToBack(e *Element[V]) @@ -216,7 +216,7 @@ func (l *List[V]) MoveToBack(e *Element[V]) MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil. -### func \(\*List\[V\]\) [MoveToFront]() +### func \(\*List\[V\]\) [MoveToFront]() ```go func (l *List[V]) MoveToFront(e *Element[V]) @@ -225,7 +225,7 @@ func (l *List[V]) MoveToFront(e *Element[V]) MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil. -### func \(\*List\[V\]\) [PushBack]() +### func \(\*List\[V\]\) [PushBack]() ```go func (l *List[V]) PushBack(v V) *Element[V] @@ -234,7 +234,7 @@ func (l *List[V]) PushBack(v V) *Element[V] PushBack inserts a new element e with value v at the back of list l and returns e. -### func \(\*List\[V\]\) [PushBackList]() +### func \(\*List\[V\]\) [PushBackList]() ```go func (l *List[V]) PushBackList(other *List[V]) @@ -243,7 +243,7 @@ func (l *List[V]) PushBackList(other *List[V]) PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil. -### func \(\*List\[V\]\) [PushFront]() +### func \(\*List\[V\]\) [PushFront]() ```go func (l *List[V]) PushFront(v V) *Element[V] @@ -252,7 +252,7 @@ func (l *List[V]) PushFront(v V) *Element[V] PushFront inserts a new element e with value v at the front of list l and returns e. -### func \(\*List\[V\]\) [PushFrontList]() +### func \(\*List\[V\]\) [PushFrontList]() ```go func (l *List[V]) PushFrontList(other *List[V]) @@ -261,7 +261,7 @@ func (l *List[V]) PushFrontList(other *List[V]) PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil. -### func \(\*List\[V\]\) [Remove]() +### func \(\*List\[V\]\) [Remove]() ```go func (l *List[V]) Remove(e *Element[V]) V diff --git a/pkg/xstl/list/example_test.go b/xstl/list/example_test.go similarity index 92% rename from pkg/xstl/list/example_test.go rename to xstl/list/example_test.go index 66fb62e..d161a61 100644 --- a/pkg/xstl/list/example_test.go +++ b/xstl/list/example_test.go @@ -7,7 +7,7 @@ package list_test import ( "fmt" - "github.com/dashjay/xiter/pkg/xstl/list" + "github.com/dashjay/xiter/xstl/list" ) func Example() { diff --git a/pkg/xstl/list/list.go b/xstl/list/list.go similarity index 100% rename from pkg/xstl/list/list.go rename to xstl/list/list.go diff --git a/pkg/xstl/list/list_test.go b/xstl/list/list_test.go similarity index 100% rename from pkg/xstl/list/list_test.go rename to xstl/list/list_test.go diff --git a/pkg/xsync/README.md b/xsync/README.md similarity index 84% rename from pkg/xsync/README.md rename to xsync/README.md index 3a25552..9fca844 100644 --- a/pkg/xsync/README.md +++ b/xsync/README.md @@ -3,7 +3,7 @@ # xsync ```go -import "github.com/dashjay/xiter/pkg/xsync" +import "github.com/dashjay/xiter/xsync" ``` package xsync provides some generics wrappers for some standard libraries like sync.Map, sync.Pool, sync.Mutext etc. @@ -49,7 +49,7 @@ package xsync provides some generics wrappers for some standard libraries like s -## type [LockedValue]() +## type [LockedValue]() LockedValue is a wrapper wrapping a value protect by a mutex @@ -60,7 +60,7 @@ type LockedValue[T any] struct { ``` -### func [NewLockedValue]() +### func [NewLockedValue]() ```go func NewLockedValue[T any](value T) *LockedValue[T] @@ -69,7 +69,7 @@ func NewLockedValue[T any](value T) *LockedValue[T] NewLockedValue returns a new LockedValue -### func \(\*LockedValue\[T\]\) [Lock]() +### func \(\*LockedValue\[T\]\) [Lock]() ```go func (l *LockedValue[T]) Lock() T @@ -78,7 +78,7 @@ func (l *LockedValue[T]) Lock() T Lock and get the value -### func \(\*LockedValue\[T\]\) [LockCB]() +### func \(\*LockedValue\[T\]\) [LockCB]() ```go func (l *LockedValue[T]) LockCB(cb func(T)) @@ -87,7 +87,7 @@ func (l *LockedValue[T]) LockCB(cb func(T)) LockCB is a shortcut for l.mu.Lock\(\) and defer l.mu.Unlock\(\) -### func \(\*LockedValue\[T\]\) [SetValue]() +### func \(\*LockedValue\[T\]\) [SetValue]() ```go func (l *LockedValue[T]) SetValue(value T) @@ -96,7 +96,7 @@ func (l *LockedValue[T]) SetValue(value T) SetValue can modify the underlying value with protection -### func \(\*LockedValue\[T\]\) [TryLock]() +### func \(\*LockedValue\[T\]\) [TryLock]() ```go func (l *LockedValue[T]) TryLock() (val T, locked bool) @@ -105,7 +105,7 @@ func (l *LockedValue[T]) TryLock() (val T, locked bool) TryLock return true with value if lock successfully, return false with zero value if lock failed -### func \(\*LockedValue\[T\]\) [Unlock]() +### func \(\*LockedValue\[T\]\) [Unlock]() ```go func (l *LockedValue[T]) Unlock() @@ -114,7 +114,7 @@ func (l *LockedValue[T]) Unlock() Unlock then the value is unprotected -## type [RWLockedValue]() +## type [RWLockedValue]() RWLockedValue is a wrapper wrapping a value protect by a RWMutex @@ -125,7 +125,7 @@ type RWLockedValue[T any] struct { ``` -### func [NewRWLockedValue]() +### func [NewRWLockedValue]() ```go func NewRWLockedValue[T any](value T) *RWLockedValue[T] @@ -134,7 +134,7 @@ func NewRWLockedValue[T any](value T) *RWLockedValue[T] NewRWLockedValue returns a new RWLockedValue -### func \(\*RWLockedValue\[T\]\) [Lock]() +### func \(\*RWLockedValue\[T\]\) [Lock]() ```go func (l *RWLockedValue[T]) Lock() T @@ -143,7 +143,7 @@ func (l *RWLockedValue[T]) Lock() T Lock and get the value -### func \(\*RWLockedValue\[T\]\) [LockCB]() +### func \(\*RWLockedValue\[T\]\) [LockCB]() ```go func (l *RWLockedValue[T]) LockCB(cb func(T)) @@ -152,7 +152,7 @@ func (l *RWLockedValue[T]) LockCB(cb func(T)) LockCB is a shortcut for l.mu.RLock\(\) and defer l.mu.RUnlock\(\) -### func \(\*RWLockedValue\[T\]\) [RLock]() +### func \(\*RWLockedValue\[T\]\) [RLock]() ```go func (l *RWLockedValue[T]) RLock() T @@ -161,7 +161,7 @@ func (l *RWLockedValue[T]) RLock() T RLock and get the value Gentleman's agreement: RLock means you should not modify the value, We cannot force a declaration that the return value cannot be modified -### func \(\*RWLockedValue\[T\]\) [RLockCB]() +### func \(\*RWLockedValue\[T\]\) [RLockCB]() ```go func (l *RWLockedValue[T]) RLockCB(cb func(T)) @@ -170,7 +170,7 @@ func (l *RWLockedValue[T]) RLockCB(cb func(T)) RLockCB is a shortcut for l.mu.RLock\(\) and defer l.mu.RUnlock\(\) -### func \(\*RWLockedValue\[T\]\) [RUnlock]() +### func \(\*RWLockedValue\[T\]\) [RUnlock]() ```go func (l *RWLockedValue[T]) RUnlock() @@ -179,7 +179,7 @@ func (l *RWLockedValue[T]) RUnlock() RUnlock then the value is unprotected -### func \(\*RWLockedValue\[T\]\) [SetValue]() +### func \(\*RWLockedValue\[T\]\) [SetValue]() ```go func (l *RWLockedValue[T]) SetValue(value T) @@ -188,7 +188,7 @@ func (l *RWLockedValue[T]) SetValue(value T) SetValue can modify the underlying value with protection -### func \(\*RWLockedValue\[T\]\) [TryLock]() +### func \(\*RWLockedValue\[T\]\) [TryLock]() ```go func (l *RWLockedValue[T]) TryLock() (val T, locked bool) @@ -197,7 +197,7 @@ func (l *RWLockedValue[T]) TryLock() (val T, locked bool) TryLock return true with value if lock successfully, return false with zero value if lock failed -### func \(\*RWLockedValue\[T\]\) [TryRLock]() +### func \(\*RWLockedValue\[T\]\) [TryRLock]() ```go func (l *RWLockedValue[T]) TryRLock() (val T, locked bool) @@ -206,7 +206,7 @@ func (l *RWLockedValue[T]) TryRLock() (val T, locked bool) TryRLock return true with value if lock successfully, return false with zero value if lock failed -### func \(\*RWLockedValue\[T\]\) [Unlock]() +### func \(\*RWLockedValue\[T\]\) [Unlock]() ```go func (l *RWLockedValue[T]) Unlock() @@ -215,7 +215,7 @@ func (l *RWLockedValue[T]) Unlock() Unlock then the value is unprotected -## type [SyncMap]() +## type [SyncMap]() SyncMap is a wrapper for sync.Map. @@ -226,7 +226,7 @@ type SyncMap[K comparable, V any] struct { ``` -### func [NewSyncMap]() +### func [NewSyncMap]() ```go func NewSyncMap[K comparable, V any]() *SyncMap[K, V] @@ -235,7 +235,7 @@ func NewSyncMap[K comparable, V any]() *SyncMap[K, V] NewSyncMap creates a new SyncMap. -### func \(\*SyncMap\[K, V\]\) [Clear]() +### func \(\*SyncMap\[K, V\]\) [Clear]() ```go func (s *SyncMap[K, V]) Clear() @@ -244,7 +244,7 @@ func (s *SyncMap[K, V]) Clear() Clear deletes all the entries, resulting in an empty Map. only available in go1.23 -### func \(\*SyncMap\[K, V\]\) [CompareAndDelete]() +### func \(\*SyncMap\[K, V\]\) [CompareAndDelete]() ```go func (s *SyncMap[K, V]) CompareAndDelete(key K, old V) bool @@ -253,7 +253,7 @@ func (s *SyncMap[K, V]) CompareAndDelete(key K, old V) bool -### func \(\*SyncMap\[K, V\]\) [CompareAndSwap]() +### func \(\*SyncMap\[K, V\]\) [CompareAndSwap]() ```go func (s *SyncMap[K, V]) CompareAndSwap(key K, old, new V) bool @@ -262,7 +262,7 @@ func (s *SyncMap[K, V]) CompareAndSwap(key K, old, new V) bool -### func \(\*SyncMap\[K, V\]\) [Delete]() +### func \(\*SyncMap\[K, V\]\) [Delete]() ```go func (s *SyncMap[K, V]) Delete(key K) @@ -271,7 +271,7 @@ func (s *SyncMap[K, V]) Delete(key K) Delete wraps sync.Map.Delete. -### func \(\*SyncMap\[K, V\]\) [Len]() +### func \(\*SyncMap\[K, V\]\) [Len]() ```go func (s *SyncMap[K, V]) Len() int @@ -280,7 +280,7 @@ func (s *SyncMap[K, V]) Len() int Len returns the number of elements in the map. The complexity is O\(n\). Not provided in stdlib but by our own -### func \(\*SyncMap\[K, V\]\) [Load]() +### func \(\*SyncMap\[K, V\]\) [Load]() ```go func (s *SyncMap[K, V]) Load(key K) (value V, ok bool) @@ -289,7 +289,7 @@ func (s *SyncMap[K, V]) Load(key K) (value V, ok bool) Load wraps sync.Map.Load. -### func \(\*SyncMap\[K, V\]\) [LoadAndDelete]() +### func \(\*SyncMap\[K, V\]\) [LoadAndDelete]() ```go func (s *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) @@ -298,7 +298,7 @@ func (s *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) LoadAndDelete wraps sync.Map.LoadAndDelete. -### func \(\*SyncMap\[K, V\]\) [LoadOrStore]() +### func \(\*SyncMap\[K, V\]\) [LoadOrStore]() ```go func (s *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) @@ -307,7 +307,7 @@ func (s *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) LoadOrStore wraps sync.Map.LoadOrStore. -### func \(\*SyncMap\[K, V\]\) [Range]() +### func \(\*SyncMap\[K, V\]\) [Range]() ```go func (s *SyncMap[K, V]) Range(f func(key K, value V) bool) @@ -316,7 +316,7 @@ func (s *SyncMap[K, V]) Range(f func(key K, value V) bool) Range wraps sync.Map.Range. -### func \(\*SyncMap\[K, V\]\) [Store]() +### func \(\*SyncMap\[K, V\]\) [Store]() ```go func (s *SyncMap[K, V]) Store(key K, value V) @@ -325,7 +325,7 @@ func (s *SyncMap[K, V]) Store(key K, value V) Store wraps sync.Map.Store. -### func \(\*SyncMap\[K, V\]\) [Swap]() +### func \(\*SyncMap\[K, V\]\) [Swap]() ```go func (s *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool) @@ -334,7 +334,7 @@ func (s *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool) -### func \(\*SyncMap\[K, V\]\) [ToMap]() +### func \(\*SyncMap\[K, V\]\) [ToMap]() ```go func (s *SyncMap[K, V]) ToMap() map[K]V @@ -343,7 +343,7 @@ func (s *SyncMap[K, V]) ToMap() map[K]V ToMap returns a copy of the map as a regular map. -## type [SyncPool]() +## type [SyncPool]() @@ -354,7 +354,7 @@ type SyncPool[T any] struct { ``` -### func [NewSyncPool]() +### func [NewSyncPool]() ```go func NewSyncPool[T any](new func() T) *SyncPool[T] @@ -363,7 +363,7 @@ func NewSyncPool[T any](new func() T) *SyncPool[T] NewSyncPool creates a new SyncPool with specified init function -### func \(\*SyncPool\[T\]\) [Get]() +### func \(\*SyncPool\[T\]\) [Get]() ```go func (s *SyncPool[T]) Get() T @@ -372,7 +372,7 @@ func (s *SyncPool[T]) Get() T Get wraps sync.Pool.Get. -### func \(\*SyncPool\[T\]\) [Put]() +### func \(\*SyncPool\[T\]\) [Put]() ```go func (s *SyncPool[T]) Put(x T) diff --git a/pkg/xsync/doc.go b/xsync/doc.go similarity index 100% rename from pkg/xsync/doc.go rename to xsync/doc.go diff --git a/pkg/xsync/locked_value.go b/xsync/locked_value.go similarity index 100% rename from pkg/xsync/locked_value.go rename to xsync/locked_value.go diff --git a/pkg/xsync/locked_value_test.go b/xsync/locked_value_test.go similarity index 100% rename from pkg/xsync/locked_value_test.go rename to xsync/locked_value_test.go diff --git a/pkg/xsync/sync_map.go b/xsync/sync_map.go similarity index 100% rename from pkg/xsync/sync_map.go rename to xsync/sync_map.go diff --git a/pkg/xsync/sync_map_1_20.go b/xsync/sync_map_1_20.go similarity index 100% rename from pkg/xsync/sync_map_1_20.go rename to xsync/sync_map_1_20.go diff --git a/pkg/xsync/sync_map_1_20_test.go b/xsync/sync_map_1_20_test.go similarity index 97% rename from pkg/xsync/sync_map_1_20_test.go rename to xsync/sync_map_1_20_test.go index 9050493..d26d3ea 100644 --- a/pkg/xsync/sync_map_1_20_test.go +++ b/xsync/sync_map_1_20_test.go @@ -6,7 +6,7 @@ package xsync_test import ( "testing" - "github.com/dashjay/xiter/pkg/xsync" + "github.com/dashjay/xiter/xsync" "github.com/stretchr/testify/assert" ) diff --git a/pkg/xsync/sync_map_1_23.go b/xsync/sync_map_1_23.go similarity index 100% rename from pkg/xsync/sync_map_1_23.go rename to xsync/sync_map_1_23.go diff --git a/pkg/xsync/sync_map_1_23_test.go b/xsync/sync_map_1_23_test.go similarity index 92% rename from pkg/xsync/sync_map_1_23_test.go rename to xsync/sync_map_1_23_test.go index 02b4589..a2ba08d 100644 --- a/pkg/xsync/sync_map_1_23_test.go +++ b/xsync/sync_map_1_23_test.go @@ -7,7 +7,7 @@ import ( "strconv" "testing" - "github.com/dashjay/xiter/pkg/xsync" + "github.com/dashjay/xiter/xsync" "github.com/stretchr/testify/assert" ) diff --git a/pkg/xsync/sync_map_test.go b/xsync/sync_map_test.go similarity index 98% rename from pkg/xsync/sync_map_test.go rename to xsync/sync_map_test.go index 6a4cc2d..0c8c5d6 100644 --- a/pkg/xsync/sync_map_test.go +++ b/xsync/sync_map_test.go @@ -8,7 +8,7 @@ import ( "sync" "testing" - "github.com/dashjay/xiter/pkg/xsync" + "github.com/dashjay/xiter/xsync" "github.com/stretchr/testify/assert" ) diff --git a/pkg/xsync/sync_pool.go b/xsync/sync_pool.go similarity index 100% rename from pkg/xsync/sync_pool.go rename to xsync/sync_pool.go diff --git a/pkg/xsync/sync_pool_test.go b/xsync/sync_pool_test.go similarity index 85% rename from pkg/xsync/sync_pool_test.go rename to xsync/sync_pool_test.go index 15f95fc..e45022e 100644 --- a/pkg/xsync/sync_pool_test.go +++ b/xsync/sync_pool_test.go @@ -3,7 +3,7 @@ package xsync_test import ( "testing" - "github.com/dashjay/xiter/pkg/xsync" + "github.com/dashjay/xiter/xsync" ) func TestSyncPool(t *testing.T) { From 07c46756c843b1507060fa7631f1a19ca2352fb8 Mon Sep 17 00:00:00 2001 From: dashjay Date: Sat, 2 May 2026 04:46:53 +0800 Subject: [PATCH 2/2] update doc --- xsync/README.md | 8 ++++---- xsync/sync_map.go | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/xsync/README.md b/xsync/README.md index 9fca844..35609eb 100644 --- a/xsync/README.md +++ b/xsync/README.md @@ -271,13 +271,13 @@ func (s *SyncMap[K, V]) Delete(key K) Delete wraps sync.Map.Delete. -### func \(\*SyncMap\[K, V\]\) [Len]() +### func \(\*SyncMap\[K, V\]\) [Len]() ```go func (s *SyncMap[K, V]) Len() int ``` -Len returns the number of elements in the map. The complexity is O\(n\). Not provided in stdlib but by our own +Len returns the number of elements in the map. The complexity is O\(n\). NOTE: Len is not concurrency\-safe. It uses sync.Map.Range internally, which does not block concurrent writes, so the count may be inaccurate if other goroutines are modifying the map concurrently. ### func \(\*SyncMap\[K, V\]\) [Load]() @@ -334,13 +334,13 @@ func (s *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool) -### func \(\*SyncMap\[K, V\]\) [ToMap]() +### func \(\*SyncMap\[K, V\]\) [ToMap]() ```go func (s *SyncMap[K, V]) ToMap() map[K]V ``` -ToMap returns a copy of the map as a regular map. +ToMap returns a copy of the map as a regular map. NOTE: ToMap is not concurrency\-safe. It uses sync.Map.Range internally, which does not block concurrent writes, so the returned map may not reflect a consistent snapshot if other goroutines are modifying the map concurrently. ## type [SyncPool]() diff --git a/xsync/sync_map.go b/xsync/sync_map.go index 8c2f322..af77296 100644 --- a/xsync/sync_map.go +++ b/xsync/sync_map.go @@ -58,7 +58,9 @@ func (s *SyncMap[K, V]) Range(f func(key K, value V) bool) { // Len returns the number of elements in the map. // The complexity is O(n). -// Not provided in stdlib but by our own +// NOTE: Len is not concurrency-safe. It uses sync.Map.Range internally, +// which does not block concurrent writes, so the count may be inaccurate +// if other goroutines are modifying the map concurrently. func (s *SyncMap[K, V]) Len() int { l := 0 s.m.Range(func(key, value any) bool { @@ -69,6 +71,10 @@ func (s *SyncMap[K, V]) Len() int { } // ToMap returns a copy of the map as a regular map. +// NOTE: ToMap is not concurrency-safe. It uses sync.Map.Range internally, +// which does not block concurrent writes, so the returned map may not +// reflect a consistent snapshot if other goroutines are modifying the +// map concurrently. func (s *SyncMap[K, V]) ToMap() map[K]V { out := make(map[K]V) s.Range(func(key K, value V) bool {