From d72f18590bec72f6321fb990f1428a12c30c00e6 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 8 Sep 2023 13:13:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20stream=20?= =?UTF-8?q?=E5=8C=85=EF=BC=8C=E6=8F=90=E4=BE=9B=E6=9B=B4=E4=BE=BF=E6=8D=B7?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/stream/map.go | 235 ++++++++-------------------- utils/stream/map_example_test.go | 26 --- utils/stream/map_test.go | 90 ----------- utils/stream/slice.go | 261 +++++++++++++++---------------- utils/stream/slice_test.go | 16 +- utils/stream/slices.go | 145 +++++++++++++++++ 6 files changed, 350 insertions(+), 423 deletions(-) delete mode 100644 utils/stream/map_example_test.go delete mode 100644 utils/stream/map_test.go create mode 100644 utils/stream/slices.go diff --git a/utils/stream/map.go b/utils/stream/map.go index a770933..1d28fbf 100644 --- a/utils/stream/map.go +++ b/utils/stream/map.go @@ -1,185 +1,88 @@ package stream import ( - "github.com/kercylan98/minotaur/utils/concurrent" "github.com/kercylan98/minotaur/utils/hash" - "reflect" ) -// WithMap 使用传入的 map 执行链式操作 -// - 该函数将会直接影响到传入的 map -func WithMap[K comparable, V any](m map[K]V) Map[K, V] { - return m -} - -// WithMapCopy 使用传入的 map 执行链式操作 -// - 该函数不会影响到传入的 map -func WithMapCopy[K comparable, V any](m map[K]V) Map[K, V] { - return hash.Copy(m) -} - -// Map 提供了 map 的链式操作 type Map[K comparable, V any] map[K]V -// Set 设置一个值 -func (slf Map[K, V]) Set(key K, value V) Map[K, V] { - slf[key] = value +// Map 返回映射 +func (slf Map[K, V]) Map() map[K]V { return slf } -// Delete 删除一个值 -func (slf Map[K, V]) Delete(key K) Map[K, V] { - delete(slf, key) +// Keys 返回键列表 +func (slf Map[K, V]) Keys() Slice[K] { + var res = make([]K, 0, len(slf)) + for key := range slf { + res = append(res, key) + } + return res +} + +// Values 返回值列表 +func (slf Map[K, V]) Values() Slice[V] { + var res = make([]V, 0, len(slf)) + for _, value := range slf { + res = append(res, value) + } + return res +} + +// Filter 是 hash.Filter 的快捷方式 +func (slf Map[K, V]) Filter(reserve bool, expression func(key K, value V) bool) Map[K, V] { + return hash.Filter(reserve, slf, expression) +} + +// FilterT 是 hash.FilterT 的快捷方式 +func (slf Map[K, V]) FilterT(expression func(key K, value V) bool) Map[K, V] { + return hash.FilterT(slf, expression) +} + +// FilterF 是 hash.FilterF 的快捷方式 +func (slf Map[K, V]) FilterF(expression func(key K, value V) bool) Map[K, V] { + return hash.FilterF(slf, expression) +} + +// FilterCopy 是 hash.FilterCopy 的快捷方式 +func (slf Map[K, V]) FilterCopy(reserve bool, expression func(key K, value V) bool) Map[K, V] { + return hash.FilterCopy(reserve, slf, expression) +} + +// FilterTCopy 是 hash.FilterTCopy 的快捷方式 +func (slf Map[K, V]) FilterTCopy(expression func(key K, value V) bool) Map[K, V] { + return hash.FilterTCopy(slf, expression) +} + +// FilterFCopy 是 hash.FilterFCopy 的快捷方式 +func (slf Map[K, V]) FilterFCopy(expression func(key K, value V) bool) Map[K, V] { + return hash.FilterFCopy(slf, expression) +} + +// Chunk 是 hash.Chunk 的快捷方式 +func (slf Map[K, V]) Chunk(size int) Slice[Map[K, V]] { + chunks := hash.Chunk(slf, size) + var res = make([]Map[K, V], 0, len(chunks)) + for i := range chunks { + res = append(res, chunks[i]) + } + return res +} + +// Each 是 hash.Each 的快捷方式 +func (slf Map[K, V]) Each(abort bool, iterator func(i int, key K, item V) bool) Map[K, V] { + hash.Each(abort, slf, iterator) return slf } -// Filter 过滤 handle 返回 false 的元素 -func (slf Map[K, V]) Filter(handle func(key K, value V) bool) Map[K, V] { - for k, v := range slf { - if !handle(k, v) { - delete(slf, k) - } - } +// EachT 是 hash.EachT 的快捷方式 +func (slf Map[K, V]) EachT(iterator func(i int, key K, item V) bool) Map[K, V] { + hash.EachT(slf, iterator) return slf } -// FilterKey 过滤特定的 key -func (slf Map[K, V]) FilterKey(keys ...K) Map[K, V] { - for _, key := range keys { - delete(slf, key) - } - return slf -} - -// FilterValue 过滤特定的 value -func (slf Map[K, V]) FilterValue(values ...V) Map[K, V] { - for k, v := range slf { - for _, value := range values { - if reflect.DeepEqual(v, value) { - delete(slf, k) - } - } - } - return slf -} - -// RandomKeep 随机保留 n 个元素 -func (slf Map[K, V]) RandomKeep(n int) Map[K, V] { - length := len(slf) - if n >= length { - return slf - } - for k := range slf { - if n > 0 { - n-- - } else { - delete(slf, k) - } - } - return slf -} - -// RandomDelete 随机删除 n 个元素 -func (slf Map[K, V]) RandomDelete(n int) Map[K, V] { - var count int - for k := range slf { - if count < n { - count++ - delete(slf, k) - } else { - return slf - } - } - return slf -} - -// RandomReplace 将 values 覆盖到当前的 map 中 -// - 如果 values 的长度大于当前 map 的长度,则只会覆盖当前 map 的长度 -func (slf Map[K, V]) RandomReplace(values ...V) Map[K, V] { - var record []K - var valuesLen = len(values) - for k := range slf { - record = append(record, k) - if len(record) >= valuesLen { - break - } - } - for i, k := range record { - slf.Set(k, values[i]) - } - return slf -} - -// Distinct 去重,如果 handle 返回 true,则认为是重复的元素 -func (slf Map[K, V]) Distinct(handle func(key K, value V) bool) Map[K, V] { - for k, v := range slf { - if handle(k, v) { - delete(slf, k) - } - } - return slf -} - -// Range 遍历当前 Map, handle 返回 false 则停止遍历 -func (slf Map[K, V]) Range(handle func(key K, value V) bool) Map[K, V] { - for k, v := range slf { - if !handle(k, v) { - break - } - } - return slf -} - -// ValueOr 当 key 不存在时,设置一个默认值 -func (slf Map[K, V]) ValueOr(key K, value V) Map[K, V] { - if _, ok := slf[key]; !ok { - slf[key] = value - } - return slf -} - -// GetValueOr 当 key 不存在时,返回一个默认值 -func (slf Map[K, V]) GetValueOr(key K, value V) V { - if v, ok := slf[key]; ok { - return v - } - return value -} - -// Clear 清空当前 Map -func (slf Map[K, V]) Clear() Map[K, V] { - for k := range slf { - delete(slf, k) - } - return slf -} - -// Merge 合并多个 Map -func (slf Map[K, V]) Merge(maps ...map[K]V) Map[K, V] { - for _, m := range maps { - for k, v := range m { - slf[k] = v - } - } - return slf -} - -// ToSliceStream 将当前 Map stream 转换为 Slice stream -func (slf Map[K, V]) ToSliceStream() Slice[V] { - return hash.ToSlice(slf) -} - -// ToSliceStreamWithKey 将当前 Map stream 转换为 Slice stream,key 为 Slice 的元素 -func (slf Map[K, V]) ToSliceStreamWithKey() Slice[K] { - return hash.KeyToSlice(slf) -} - -// ToSyncMap 将当前 Map 转换为 concurrent.BalanceMap -func (slf Map[K, V]) ToSyncMap() *concurrent.BalanceMap[K, V] { - return concurrent.NewBalanceMap[K, V](concurrent.WithBalanceMapSource(slf)) -} - -// ToMap 将当前 Map 转换为 map -func (slf Map[K, V]) ToMap() map[K]V { +// EachF 是 hash.EachF 的快捷方式 +func (slf Map[K, V]) EachF(iterator func(i int, key K, item V) bool) Map[K, V] { + hash.EachF(slf, iterator) return slf } diff --git a/utils/stream/map_example_test.go b/utils/stream/map_example_test.go deleted file mode 100644 index 1989c21..0000000 --- a/utils/stream/map_example_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package stream_test - -import ( - "fmt" - "github.com/kercylan98/minotaur/utils/stream" -) - -func ExampleWithMap() { - m := stream.WithMap(map[int]string{1: "a", 2: "b", 3: "c", 4: "d", 5: "d"}).Filter(func(key int, value string) bool { - return key > 3 - }) - fmt.Println(len(m)) - - // Output: - // 2 -} - -func ExampleWithMapCopy() { - m := stream.WithMapCopy(map[int]string{1: "a", 2: "b", 3: "c", 4: "d", 5: "d"}).Filter(func(key int, value string) bool { - return key > 3 - }) - fmt.Println(len(m)) - - // Output: - // 2 -} diff --git a/utils/stream/map_test.go b/utils/stream/map_test.go deleted file mode 100644 index 270ca2f..0000000 --- a/utils/stream/map_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package stream_test - -import ( - "github.com/kercylan98/minotaur/utils/stream" - . "github.com/smartystreets/goconvey/convey" - "testing" -) - -func initMap() map[int]int { - return map[int]int{ - 1: 100, - 2: 200, - 3: 300, - } -} - -func TestWithMap(t *testing.T) { - Convey("TestWithMap", t, func() { - var s = initMap() - var m = stream.WithMap(s).RandomDelete(1) - So(m, ShouldNotBeNil) - So(len(s), ShouldEqual, 2) - }) -} - -func TestWithMapCopy(t *testing.T) { - Convey("TestWithMapCopy", t, func() { - var s = initMap() - var m = stream.WithMapCopy(s).RandomDelete(1) - So(m, ShouldNotBeNil) - So(len(s), ShouldEqual, 3) - }) -} - -func TestMap_Set(t *testing.T) { - Convey("TestMap_Set", t, func() { - var m = stream.WithMap(initMap()).Set(4, 400) - So(m[4], ShouldEqual, 400) - }) -} - -func TestMap_Filter(t *testing.T) { - Convey("TestMap_Filter", t, func() { - var m = stream.WithMap(initMap()).Filter(func(key int, value int) bool { - return key == 1 - }) - So(len(m), ShouldEqual, 1) - }) -} - -func TestMap_FilterKey(t *testing.T) { - Convey("TestMap_FilterKey", t, func() { - var m = stream.WithMap(initMap()).FilterKey(1) - So(len(m), ShouldEqual, 2) - }) -} - -func TestMap_FilterValue(t *testing.T) { - Convey("TestMap_FilterValue", t, func() { - var m = stream.WithMap(initMap()).FilterValue(100) - So(len(m), ShouldEqual, 2) - }) -} - -func TestMap_RandomKeep(t *testing.T) { - Convey("TestMap_RandomKeep", t, func() { - var m = stream.WithMap(initMap()).RandomKeep(1) - So(len(m), ShouldEqual, 1) - }) -} - -func TestMap_RandomDelete(t *testing.T) { - Convey("TestMap_RandomDelete", t, func() { - var m = stream.WithMap(initMap()).RandomDelete(1) - So(len(m), ShouldEqual, 2) - }) -} - -func TestMap_Distinct(t *testing.T) { - Convey("TestMap_Distinct", t, func() { - var m = stream.WithMap(map[int]int{ - 1: 100, - 2: 200, - 3: 100, - }).Distinct(func(key int, value int) bool { - return value == 100 - }) - So(len(m), ShouldEqual, 1) - }) -} diff --git a/utils/stream/slice.go b/utils/stream/slice.go index 34d21ba..00fe381 100644 --- a/utils/stream/slice.go +++ b/utils/stream/slice.go @@ -1,152 +1,151 @@ package stream -import ( - "github.com/kercylan98/minotaur/utils/hash" - "github.com/kercylan98/minotaur/utils/slice" - "reflect" -) +import "github.com/kercylan98/minotaur/utils/slice" -// WithSlice 创建一个 Slice -// - 该函数不会影响到传入的 slice -func WithSlice[V any](values []V) Slice[V] { - return slice.Copy(values) -} - -// Slice 提供了 slice 的链式操作 type Slice[V any] []V -// Filter 过滤 handle 返回 false 的元素 -func (slf Slice[V]) Filter(handle func(index int, value V) bool) Slice[V] { - var ns = make([]V, 0, len(slf)) - for i, v := range slf { - if handle(i, v) { - ns = append(ns, v) - } - } - return ns +// Slice 返回切片 +func (slf Slice[V]) Slice() []V { + return slf } -// FilterValue 过滤特定的 value -func (slf Slice[V]) FilterValue(values ...V) Slice[V] { - return slf.Filter(func(index int, value V) bool { - for _, v := range values { - if reflect.DeepEqual(v, value) { - return false - } - } - return true - }) +// Chunk 的快捷方式 +func (slf Slice[V]) Chunk(size int) Slices[V] { + chunks := slice.Chunk(slf, size) + result := make(Slices[V], len(chunks)) + for i, chunk := range chunks { + result[i] = chunk + } + return result } -// FilterIndex 过滤特定的 index -func (slf Slice[V]) FilterIndex(indexes ...int) Slice[V] { - return slf.Filter(func(index int, value V) bool { - return !slice.Contains(indexes, index) - }) +// Drop 是 slice.Drop 的快捷方式 +func (slf Slice[V]) Drop(start, n int) Slice[V] { + return slice.Drop(start, n, slf) } -// RandomKeep 随机保留 n 个元素 -func (slf Slice[V]) RandomKeep(n int) Slice[V] { - length := len(slf) - if n >= length { - return slf - } - var hit = make([]int, length) - for i := 0; i < n; i++ { - hit[i] = 1 - } - slice.Shuffle(hit) - var ns = make([]V, 0, n) - for i, v := range slf { - if hit[i] == 1 { - ns = append(ns, v) - } - } - return ns +// DropBy 是 slice.DropBy 的快捷方式 +func (slf Slice[V]) DropBy(fn func(index int, value V) bool) Slice[V] { + return slice.DropBy(slf, fn) } -// RandomDelete 随机删除 n 个元素 -func (slf Slice[V]) RandomDelete(n int) Slice[V] { - length := len(slf) - if n >= length { - return slf[:0] - } - var hit = make([]int, length) - for i := 0; i < n; i++ { - hit[i] = 1 - } - slice.Shuffle(hit) - var ns = make([]V, 0, n) - for i, v := range slf { - if hit[i] == 0 { - ns = append(ns, v) - } - } - return ns +// Each 是 slice.Each 的快捷方式 +func (slf Slice[V]) Each(abort bool, iterator func(index int, item V) bool) Slice[V] { + slice.Each(abort, slf, iterator) + return slf } -// Shuffle 随机打乱 +// EachT 是 slice.EachT 的快捷方式 +func (slf Slice[V]) EachT(iterator func(index int, item V) bool) Slice[V] { + slice.EachT(slf, iterator) + return slf +} + +// EachF 是 slice.EachF 的快捷方式 +func (slf Slice[V]) EachF(iterator func(index int, item V) bool) Slice[V] { + slice.EachF(slf, iterator) + return slf +} + +// EachReverse 是 slice.EachReverse 的快捷方式 +func (slf Slice[V]) EachReverse(abort bool, iterator func(index int, item V) bool) Slice[V] { + slice.EachReverse(abort, slf, iterator) + return slf +} + +// EachReverseT 是 slice.EachReverseT 的快捷方式 +func (slf Slice[V]) EachReverseT(iterator func(index int, item V) bool) Slice[V] { + slice.EachReverseT(slf, iterator) + return slf +} + +// EachReverseF 是 slice.EachReverseF 的快捷方式 +func (slf Slice[V]) EachReverseF(iterator func(index int, item V) bool) Slice[V] { + slice.EachReverseF(slf, iterator) + return slf +} + +// FillBy 是 slice.FillBy 的快捷方式 +func (slf Slice[V]) FillBy(fn func(index int, value V) V) Slice[V] { + return slice.FillBy(slf, fn) +} + +// FillByCopy 是 slice.FillByCopy 的快捷方式 +func (slf Slice[V]) FillByCopy(fn func(index int, value V) V) Slice[V] { + return slice.FillByCopy(slf, fn) +} + +// FillUntil 是 slice.FillUntil 的快捷方式 +func (slf Slice[V]) FillUntil(abort bool, fn func(index int, value V) (V, bool)) Slice[V] { + return slice.FillUntil(abort, slf, fn) +} + +// FillUntilCopy 是 slice.FillUntilCopy 的快捷方式 +func (slf Slice[V]) FillUntilCopy(abort bool, fn func(index int, value V) (V, bool)) Slice[V] { + return slice.FillUntilCopy(abort, slf, fn) +} + +// FillUntilT 是 slice.FillUntilT 的快捷方式 +func (slf Slice[V]) FillUntilT(fn func(index int, value V) (V, bool)) Slice[V] { + return slice.FillUntilT(slf, fn) +} + +// FillUntilF 是 slice.FillUntilF 的快捷方式 +func (slf Slice[V]) FillUntilF(fn func(index int, value V) (V, bool)) Slice[V] { + return slice.FillUntilF(slf, fn) +} + +// FillUntilTCopy 是 slice.FillUntilTCopy 的快捷方式 +func (slf Slice[V]) FillUntilTCopy(fn func(index int, value V) (V, bool)) Slice[V] { + return slice.FillUntilTCopy(slf, fn) +} + +// FillUntilFCopy 是 slice.FillUntilFCopy 的快捷方式 +func (slf Slice[V]) FillUntilFCopy(fn func(index int, value V) (V, bool)) Slice[V] { + return slice.FillUntilFCopy(slf, fn) +} + +// Filter 是 slice.Filter 的快捷方式 +func (slf Slice[V]) Filter(reserve bool, expression func(index int, item V) bool) Slice[V] { + return slice.Filter(reserve, slf, expression) +} + +// FilterT 是 slice.FilterT 的快捷方式 +func (slf Slice[V]) FilterT(expression func(index int, item V) bool) Slice[V] { + return slice.FilterT(slf, expression) +} + +// FilterF 是 slice.FilterF 的快捷方式 +func (slf Slice[V]) FilterF(expression func(index int, item V) bool) Slice[V] { + return slice.FilterF(slf, expression) +} + +// FilterCopy 是 slice.FilterCopy 的快捷方式 +func (slf Slice[V]) FilterCopy(reserve bool, expression func(index int, item V) bool) Slice[V] { + return slice.FilterCopy(reserve, slf, expression) +} + +// FilterTCopy 是 slice.FilterTCopy 的快捷方式 +func (slf Slice[V]) FilterTCopy(expression func(index int, item V) bool) Slice[V] { + return slice.FilterTCopy(slf, expression) +} + +// FilterFCopy 是 slice.FilterFCopy 的快捷方式 +func (slf Slice[V]) FilterFCopy(expression func(index int, item V) bool) Slice[V] { + return slice.FilterFCopy(slf, expression) +} + +// Shuffle 是 slice.Shuffle 的快捷方式 func (slf Slice[V]) Shuffle() Slice[V] { - slice.Shuffle(slf) - return slf + return slice.Shuffle(slf) } -// Reverse 反转 -func (slf Slice[V]) Reverse() Slice[V] { - slice.Reverse(slf) - return slf +// ShuffleCopy 是 slice.ShuffleCopy 的快捷方式 +func (slf Slice[V]) ShuffleCopy() Slice[V] { + return slice.ShuffleCopy(slf) } -// Clear 清空 -func (slf Slice[V]) Clear() Slice[V] { - return slf[:0] -} - -// Distinct 去重,如果 handle 返回 true 则认为是重复元素 -func (slf Slice[V]) Distinct() Slice[V] { - return slice.Distinct(slf) -} - -// Merge 合并 -func (slf Slice[V]) Merge(values ...V) Slice[V] { - return append(slf, values...) -} - -// GetStartPart 获取前 n 个元素 -func (slf Slice[V]) GetStartPart(n int) Slice[V] { - return slf[:n] -} - -// GetEndPart 获取后 n 个元素 -func (slf Slice[V]) GetEndPart(n int) Slice[V] { - return slice.GetEndPart(slf, n) -} - -// GetPart 获取指定区间的元素 -func (slf Slice[V]) GetPart(start, end int) Slice[V] { - return slice.GetPart(slf, start, end) -} - -// ContainsHandle 如果包含指定的元素则执行 handle -func (slf Slice[V]) ContainsHandle(value V, handle func(slice Slice[V]) Slice[V]) Slice[V] { - if slice.ContainsAny(slf, value) { - return handle(slf) - } - return slf -} - -// Set 设置指定位置的元素 -func (slf Slice[V]) Set(index int, value V) Slice[V] { - slf[index] = value - return slf -} - -// Delete 删除指定位置的元素 -func (slf Slice[V]) Delete(index int) Slice[V] { - return append(slf, slf[index+1:]...) -} - -// ToMapStream 将当前的 Slice stream 转换为 Map stream -func (slf Slice[V]) ToMapStream() Map[int, V] { - return hash.ToMap(slf) +// UniqueBy 是 slice.UniqueBy 的快捷方式 +func (slf Slice[V]) UniqueBy(fn func(V) any) Slice[V] { + return slice.UniqueBy(slf, fn) } diff --git a/utils/stream/slice_test.go b/utils/stream/slice_test.go index 1dff0e4..41921c8 100644 --- a/utils/stream/slice_test.go +++ b/utils/stream/slice_test.go @@ -1,18 +1,14 @@ package stream_test import ( - "fmt" "github.com/kercylan98/minotaur/utils/stream" - . "github.com/smartystreets/goconvey/convey" "testing" ) -func TestSlice_Filter(t *testing.T) { - Convey("TestSlice_Filter", t, func() { - d := []int{1, 2, 3, 4, 5} - var s = stream.WithSlice(d).Reverse() - fmt.Println(s) - fmt.Println(d) - So(len(s), ShouldEqual, 2) - }) +func TestStream_Chunk(t *testing.T) { + var s = stream.Slice[int]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + var chunks = s.Chunk(3) + for _, chunk := range chunks { + t.Log(chunk) + } } diff --git a/utils/stream/slices.go b/utils/stream/slices.go new file mode 100644 index 0000000..e0d7ca1 --- /dev/null +++ b/utils/stream/slices.go @@ -0,0 +1,145 @@ +package stream + +import "github.com/kercylan98/minotaur/utils/slice" + +type Slices[V any] []Slice[V] + +// Merge 合并为一个切片 +func (slf Slices[V]) Merge() Slice[V] { + var s = make([]V, 0) + for _, stream := range slf { + s = append(s, stream...) + } + return s +} + +// Drop 的快捷方式 +func (slf Slices[V]) Drop(start, n int) Slices[V] { + return slice.Drop(start, n, slf) +} + +// DropBy 的快捷方式 +func (slf Slices[V]) DropBy(fn func(index int, value Slice[V]) bool) Slices[V] { + return slice.DropBy(slf, fn) +} + +// Each 的快捷方式 +func (slf Slices[V]) Each(abort bool, iterator func(index int, item Slice[V]) bool) Slices[V] { + slice.Each(abort, slf, iterator) + return slf +} + +// EachT 的快捷方式 +func (slf Slices[V]) EachT(iterator func(index int, item Slice[V]) bool) Slices[V] { + slice.EachT(slf, iterator) + return slf +} + +// EachF 的快捷方式 +func (slf Slices[V]) EachF(iterator func(index int, item Slice[V]) bool) Slices[V] { + slice.EachF(slf, iterator) + return slf +} + +// EachReverse 的快捷方式 +func (slf Slices[V]) EachReverse(abort bool, iterator func(index int, item Slice[V]) bool) Slices[V] { + slice.EachReverse(abort, slf, iterator) + return slf +} + +// EachReverseT 的快捷方式 +func (slf Slices[V]) EachReverseT(iterator func(index int, item Slice[V]) bool) Slices[V] { + slice.EachReverseT(slf, iterator) + return slf +} + +// EachReverseF 的快捷方式 +func (slf Slices[V]) EachReverseF(iterator func(index int, item Slice[V]) bool) Slices[V] { + slice.EachReverseF(slf, iterator) + return slf +} + +// FillBy 的快捷方式 +func (slf Slices[V]) FillBy(fn func(index int, value Slice[V]) Slice[V]) Slices[V] { + return slice.FillBy(slf, fn) +} + +// FillByCopy 的快捷方式 +func (slf Slices[V]) FillByCopy(fn func(index int, value Slice[V]) Slice[V]) Slices[V] { + return slice.FillByCopy(slf, fn) +} + +// FillUntil 的快捷方式 +func (slf Slices[V]) FillUntil(abort bool, fn func(index int, value Slice[V]) (Slice[V], bool)) Slices[V] { + return slice.FillUntil(abort, slf, fn) +} + +// FillUntilCopy 的快捷方式 +func (slf Slices[V]) FillUntilCopy(abort bool, fn func(index int, value Slice[V]) (Slice[V], bool)) Slices[V] { + return slice.FillUntilCopy(abort, slf, fn) +} + +// FillUntilT 的快捷方式 +func (slf Slices[V]) FillUntilT(fn func(index int, value Slice[V]) (Slice[V], bool)) Slices[V] { + return slice.FillUntilT(slf, fn) +} + +// FillUntilF 的快捷方式 +func (slf Slices[V]) FillUntilF(fn func(index int, value Slice[V]) (Slice[V], bool)) Slices[V] { + return slice.FillUntilF(slf, fn) +} + +// FillUntilTCopy 的快捷方式 +func (slf Slices[V]) FillUntilTCopy(fn func(index int, value Slice[V]) (Slice[V], bool)) Slices[V] { + return slice.FillUntilTCopy(slf, fn) +} + +// FillUntilFCopy 的快捷方式 +func (slf Slices[V]) FillUntilFCopy(fn func(index int, value Slice[V]) (Slice[V], bool)) Slices[V] { + return slice.FillUntilFCopy(slf, fn) +} + +// Filter 的快捷方式 +func (slf Slices[V]) Filter(reserve bool, expression func(index int, item Slice[V]) bool) Slices[V] { + return slice.Filter(reserve, slf, expression) +} + +// FilterT 的快捷方式 +func (slf Slices[V]) FilterT(expression func(index int, item Slice[V]) bool) Slices[V] { + return slice.FilterT(slf, expression) +} + +// FilterF 的快捷方式 +func (slf Slices[V]) FilterF(expression func(index int, item Slice[V]) bool) Slices[V] { + return slice.FilterF(slf, expression) +} + +// FilterCopy 的快捷方式 +func (slf Slices[V]) FilterCopy(reserve bool, expression func(index int, item Slice[V]) bool) Slices[V] { + return slice.FilterCopy(reserve, slf, expression) +} + +// FilterTCopy 的快捷方式 +func (slf Slices[V]) FilterTCopy(expression func(index int, item Slice[V]) bool) Slices[V] { + return slice.FilterTCopy(slf, expression) +} + +// FilterFCopy 的快捷方式 +func (slf Slices[V]) FilterFCopy(expression func(index int, item Slice[V]) bool) Slices[V] { + return slice.FilterFCopy(slf, expression) +} + +// Shuffle 的快捷方式 +func (slf Slices[V]) Shuffle() Slices[V] { + return slice.Shuffle(slf) +} + +// ShuffleCopy 的快捷方式 +func (slf Slices[V]) ShuffleCopy() Slices[V] { + return slice.ShuffleCopy(slf) +} + +// UniqueBy 的快捷方式 +func (slf Slices[V]) UniqueBy(fn func(Slice[V]) any) Slices[V] { + return slice.UniqueBy(slf, fn) +}