Documentation ¶
Index ¶
- func Associate[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
- func Chunk[T any](collection []T, size int) [][]T
- func Compact[T comparable](collection []T) []T
- func Contains[T comparable](collection []T, element T) bool
- func ContainsBy[T any](collection []T, predicate func(item T) bool) bool
- func Count[T comparable](collection []T, value T) (count int)
- func CountBy[T any](collection []T, predicate func(item T) bool) (count int)
- func CountValues[T comparable](collection []T) map[T]int
- func CountValuesBy[T any, U comparable](collection []T, mapper func(item T) U) map[U]int
- func Difference[T comparable](list1 []T, list2 []T) ([]T, []T)
- func DistinctInt(slice []int) []int
- func DistinctItem[T any](slice []T, compare func(T, T) bool) []T
- func DistinctStr(slice []string) []string
- func Drop[T any](collection []T, n int) []T
- func DropRight[T any](collection []T, n int) []T
- func DropRightWhile[T any](collection []T, predicate func(item T) bool) []T
- func DropWhile[T any](collection []T, predicate func(item T) bool) []T
- func Every[T comparable](collection []T, subset []T) bool
- func EveryBy[T any](collection []T, predicate func(item T) bool) bool
- func Fill[T Cloneable[T]](collection []T, initial T) []T
- func Filter[T any](collection []T, predicate func(item T, index int) bool) []T
- func FilterMap[T any, R any](collection []T, callback func(item T, index int) (R, bool)) []R
- func FindIndex[T any](s []T, compare func(T) bool) (int, bool)
- func FindIntIndex(slice []int, val int) (int, bool)
- func FindLastIndexOf[T any](collection []T, predicate func(item T) bool) (int, bool)
- func FindStrIndex(slice []string, val string) (int, bool)
- func FlatMap[T any, R any](collection []T, iteratee func(item T, index int) []R) []R
- func Flatten[T any](collection [][]T) []T
- func ForEach[T any](collection []T, iteratee func(item T, index int))
- func GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T
- func Interleave[T any](collections ...[]T) []T
- func Intersect[T comparable](list1 []T, list2 []T) []T
- func IsSorted[T Ordered](collection []T) bool
- func IsSortedByKey[T any, K Ordered](collection []T, iteratee func(item T) K) bool
- func KeyBy[K comparable, V any](collection []V, iteratee func(item V) K) map[K]V
- func Last[T any](collection []T) (T, error)
- func LastIndexOf[T comparable](collection []T, element T) int
- func Map[T any, R any](collection []T, iteratee func(item T, index int) R) []R
- func Max[T Ordered](collection []T) T
- func MaxBy[T any](collection []T, comparison func(a T, b T) bool) T
- func Min[T Ordered](collection []T) T
- func MinBy[T any](collection []T, comparison func(a T, b T) bool) T
- func None[T comparable](collection []T, subset []T) bool
- func NoneBy[T any](collection []T, predicate func(item T) bool) bool
- func Nth[T any, N Integer](collection []T, nth N) (T, error)
- func ParallelForEach[T any](collection []T, iteratee func(item T, index int))
- func ParallelGroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T
- func ParallelMap[T any, R any](collection []T, iteratee func(item T, index int) R) []R
- func ParallelPartitionBy[T any, K comparable](collection []T, iteratee func(item T) K) [][]T
- func ParallelTimes[T any](count int, iteratee func(index int) T) []T
- func PartitionBy[T any, K comparable](collection []T, iteratee func(item T) K) [][]T
- func Range(elementNum int) []int
- func RangeFrom[T Integer | Float](start T, elementNum int) []T
- func RangeWithStep[T Integer | Float](start, end, step T) []T
- func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func ReduceRight[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
- func Reject[V any](collection []V, predicate func(item V, index int) bool) []V
- func RemoveAllItem[T any](s []T, compare func(T) bool) []T
- func RemoveFirstItem[T any](s []T, compare func(T) bool) []T
- func Repeat[T Cloneable[T]](count int, initial T) []T
- func RepeatBy[T any](count int, predicate func(index int) T) []T
- func Replace[T comparable](collection []T, old T, new T, n int) []T
- func ReplaceAll[T comparable](collection []T, old T, new T) []T
- func Reverse[T any](collection []T) []T
- func Shuffle[T any](collection []T) []T
- func Slice[T any](collection []T, start int, end int) []T
- func SliceDiff[T any](s1 []T, s2 []T, compare func(T, T) bool) []T
- func SliceIntersect[T any](s1 []T, s2 []T, compare func(T, T) bool) []T
- func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
- func Some[T comparable](collection []T, subset []T) bool
- func SomeBy[T any](collection []T, predicate func(item T) bool) bool
- func Subset[T any](collection []T, offset int, length uint) []T
- func Sum[T Float | Integer | Complex](collection []T) T
- func SumBy[T any, R Float | Integer | Complex](collection []T, iteratee func(item T) R) R
- func Times[T any](count int, iteratee func(index int) T) []T
- func ToSlicePtr[T any](collection []T) []*T
- func Union[T comparable](lists ...[]T) []T
- func Uniq[T comparable](collection []T) []T
- func UniqBy[T any, U comparable](collection []T, iteratee func(item T) U) []T
- func Without[T comparable](collection []T, exclude ...T) []T
- func WithoutEmpty[T comparable](collection []T) []T
- type Cloneable
- type Complex
- type Float
- type Integer
- type Ordered
- type Signed
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Associate ¶ added in v1.2.0
func Associate[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
Associate 类似KeyBy,将切片转换为map,key为切片原数据,value为函数处理的结果.如果存在重复的,则忽略掉. Play: https://go.dev/play/p/WHa2CfMO3Lr
func Chunk ¶ added in v1.2.0
Chunk 返回一个元素数组,将其分成长度为size的小切片.如果切片不能被平均分割,最后一个块将是剩余的元素. @param: collection 切片 @param: size 每个切片分组里数据的大小
func Compact ¶ added in v1.2.0
func Compact[T comparable](collection []T) []T
Compact 清除切片空值 Play: https://go.dev/play/p/tXiy-iK6PAc
func Contains ¶ added in v1.2.0
func Contains[T comparable](collection []T, element T) bool
Contains 判断切片是否包含指定的元素 @param: collection 原切片数据 @param: element 查找的数据
func ContainsBy ¶ added in v1.2.0
ContainsBy 和FindIndex类似,判断切片是否包含指定的元素(根据指定的函数) @param: collection 原切片数据 @param: predicate 进行比较的函数
func Count ¶ added in v1.2.0
func Count[T comparable](collection []T, value T) (count int)
Count 统计元素出现的次数 Play: https://go.dev/play/p/Y3FlK54yveC
func CountBy ¶ added in v1.2.0
CountBy 统计满足条件元素出现的次数 Play: https://go.dev/play/p/ByQbNYQQi4X
func CountValues ¶ added in v1.2.0
func CountValues[T comparable](collection []T) map[T]int
CountValues 统计切片里元素出现的次数,返回的map,key为切片的元素,value为次数 Play: https://go.dev/play/p/-p-PyLT4dfy
func CountValuesBy ¶ added in v1.2.0
func CountValuesBy[T any, U comparable](collection []T, mapper func(item T) U) map[U]int
CountValuesBy 统计切片里元素满足条件的次数,返回的map,key为函数的结果,value为满足的元素个数 Play: https://go.dev/play/p/2U0dG1SnOmS
func Difference ¶ added in v1.2.0
func Difference[T comparable](list1 []T, list2 []T) ([]T, []T)
Difference 和SliceDiff一样,计算2个集合的交集
func DistinctItem ¶ added in v1.1.4
DistinctItem 数组去重
func Drop ¶ added in v1.2.0
Drop 从开头丢弃n个元素 Play: https://go.dev/play/p/JswS7vXRJP2
func DropRight ¶ added in v1.2.0
DropRight 从结尾丢弃n个元素. Play: https://go.dev/play/p/GG0nXkSJJa3
func DropRightWhile ¶ added in v1.2.0
DropRightWhile DropWhile的尾部丢弃 Play: https://go.dev/play/p/3-n71oEC0Hz
func DropWhile ¶ added in v1.2.0
DropWhile 类似于Filter,丢弃满足条件的索引前面的数据 Play: https://go.dev/play/p/7gBPYw2IK16
func Every ¶ added in v1.2.0
func Every[T comparable](collection []T, subset []T) bool
Every 判断一个切片是否完全包含另一个切片 @param: collection 大切片 @param: subset 小切片
func EveryBy ¶ added in v1.2.0
EveryBy 判断一个切片的元素进行函数计算全部返回true @param: collection 大切片 @param: predicate 计算函数
func Fill ¶ added in v1.2.0
func Fill[T Cloneable[T]](collection []T, initial T) []T
Fill 用"初始值"填充数组元素,initial需要实现Cloneable接口 https://go.dev/play/p/VwR34GzqEub
func Filter ¶ added in v1.2.0
Filter 遍历集合的元素,返回满足条件的元素 @param: collection原切片 @param: predicate执行计算的函数,返回true才满足过滤的条件
func FilterMap ¶ added in v1.2.0
FilterMap 遍历切片并根据给定的函数计算的结果,将原切片数据计算结果为true,计算后的数据合并至新的切片 @param: collection原切片 @param: callback执行计算的函数,返true才将计算的结果合并至新的切片
func FindLastIndexOf ¶ added in v1.2.0
FindLastIndexOf 查询泛型在切片里最后一次的位置
func FindStrIndex ¶
FindStrIndex 查询字符串在切片里的位置
func FlatMap ¶ added in v1.2.0
FlatMap 操作切片并将其转换和展平为另一种类型的切片 创建一个扁平化(注:同阶数组)的切片,这个切片的值来自collection(切片)中的每一个值经过iteratee(迭代函数)处理后返回的结果,并且扁平化合并. @param: collection原切片 @param: iteratee执行计算的函数,函数计算的结果是一个新的切片
func Flatten ¶ added in v1.2.0
func Flatten[T any](collection [][]T) []T
Flatten 返回深度仅为一级的切片,即二维切片转换为一维切片
func GroupBy ¶ added in v1.2.0
func GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T
GroupBy 返回由通过iteratee运行集合的每个元素的结果生成的键组成的对象 @param: collection切片 @param: accumulator执行计算的函数,根据函数的结果进行分组,函数的结果作为分组后map的key,value是计算结果相同的元素的切片
func Interleave ¶ added in v1.2.0
func Interleave[T any](collections ...[]T) []T
Interleave 循环交替输入切片,并依次在索引处追加值到结果中
func Intersect ¶ added in v1.2.0
func Intersect[T comparable](list1 []T, list2 []T) []T
Intersect 和SliceIntersect一样,计算2个切片的交集
func IsSorted ¶ added in v1.2.0
IsSorted 检查切片是否是已排序的 Play: https://go.dev/play/p/mc3qR-t4mcx
func IsSortedByKey ¶ added in v1.2.0
IsSortedByKey 检查一个切片是否按iteratee函数的结果排序. Play: https://go.dev/play/p/wiG6XyBBu49
func KeyBy ¶ added in v1.2.0
func KeyBy[K comparable, V any](collection []V, iteratee func(item V) K) map[K]V
KeyBy 将切片转换为map,key为函数处理的结果,value为切片元数据. Play: https://go.dev/play/p/mdaClUAT-zZ
func LastIndexOf ¶ added in v1.2.0
func LastIndexOf[T comparable](collection []T, element T) int
LastIndexOf 返回数组中最后出现的值所在的索引,没有找到的话返回-1
func Map ¶ added in v1.2.0
Map 遍历切片并根据给定的函数将原切片值进行转换后合并为一个新的切片 @param: collection原切片 @param: iteratee执行计算的函数,返回计算后的数据后合并至新的切片
func None ¶ added in v1.2.0
func None[T comparable](collection []T, subset []T) bool
None 如果切片中没有包含子集的元素(和子集的元素没有重叠),或者子集为空,则返回true
func Nth ¶ added in v1.2.0
Nth returns the element at index `nth` of collection. If `nth` is negative, the nth element from the end is returned. An error is returned when nth is out of slice bounds.
func ParallelForEach ¶ added in v1.2.0
ParallelForEach ForEach的多协程版本
func ParallelGroupBy ¶ added in v1.2.0
func ParallelGroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T
ParallelGroupBy GroupBy的多协程版本
func ParallelMap ¶ added in v1.2.0
ParallelMap Map的多协程版本
func ParallelPartitionBy ¶ added in v1.2.0
func ParallelPartitionBy[T any, K comparable](collection []T, iteratee func(item T) K) [][]T
ParallelPartitionBy PartitionBy的多协程版本
func ParallelTimes ¶ added in v1.2.0
ParallelTimes Times的多携程版本
func PartitionBy ¶ added in v1.2.0
func PartitionBy[T any, K comparable](collection []T, iteratee func(item T) K) [][]T
PartitionBy 和GroupBy类似,返回拆分为组的元素切片.分组是通过iteratee运行切片的每个元素的结果生成的.
func Range ¶ added in v1.2.0
Range 根据给定的长度创建切片 Play: https://go.dev/play/p/0r6VimXAi9H
func RangeFrom ¶ added in v1.2.0
RangeFrom 根据给定的其实数值和长度创建切片 Play: https://go.dev/play/p/0r6VimXAi9H
func RangeWithStep ¶ added in v1.2.0
RangeWithStep 给定开始值和结束值,按照步长生成切片 @param: start 开始值 @param: end 结束值 @param: step 步长
func Reduce ¶ added in v1.2.0
func Reduce[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
Reduce 将切片缩减为一个值,该值是通过累加器运行切片中每个元素的累积结果,其中每次连续调用都提供前一次调用的返回值. 压缩 collection(切片)为一个值,通过 iteratee(迭代函数)遍历 collection(切片)中的每个元素,每次返回的值会作为下一次迭代使用(注:作为iteratee(迭代函数)的第一个参数使用). @param: collection切片 @param: accumulator执行计算的函数,agg:每一次计算的初始值,item:切片的元素,index:切片的元素索引 @param: initial初始值
func ReduceRight ¶ added in v1.2.0
func ReduceRight[T any, R any](collection []T, accumulator func(agg R, item T, index int) R, initial R) R
ReduceRight 从尾向头开始reduce操作 Play: https://go.dev/play/p/Fq3W70l7wXF
func Reject ¶ added in v1.2.0
Reject 是Filter的相反切片,排除掉返回结果为true的元素 Play: https://go.dev/play/p/YkLMODy1WEL
func RemoveAllItem ¶
RemoveAllItem 从切片中移除所有匹配的元素
func RemoveFirstItem ¶
RemoveFirstItem 从切片中移除第一个匹配元素
func Repeat ¶ added in v1.2.0
Repeat 构建包含N个T元素副本的切片 Play: https://go.dev/play/p/g3uHXbmc3b6
func RepeatBy ¶ added in v1.2.0
RepeatBy 根据函数predicate构建包含N个副本的切片. Play: https://go.dev/play/p/ozZLCtX_hNU
func Replace ¶ added in v1.2.0
func Replace[T comparable](collection []T, old T, new T, n int) []T
Replace 替换切片里的数据 @param: collection 原切片数据 @param: old 待替换的旧数据 @param: new 替换的新数据 @param: n 替换的次数 Play: https://go.dev/play/p/XfPzmf9gql6
func ReplaceAll ¶ added in v1.2.0
func ReplaceAll[T comparable](collection []T, old T, new T) []T
ReplaceAll 替换切片里所有匹配的数据 @param: collection 原切片数据 @param: old 待替换的旧数据 @param: new 替换的新数据 Play: https://go.dev/play/p/a9xZFUHfYcV
func Shuffle ¶ added in v1.2.0
func Shuffle[T any](collection []T) []T
Shuffle 创建一个被打乱值的集合.使用Fisher-Yates shuffle算法。
func Slice ¶ added in v1.2.0
Slice 从开始位置和结束位置截取切片 @param: collection 原切片数据 @param: start 开始位置,包含 @param: end 结束位置,不包含 Play: https://go.dev/play/p/8XWYhfMMA1h
func SliceIntersect ¶
SliceIntersect 2个切片的交集
func SliceToMap ¶ added in v1.2.0
func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
SliceToMap Associate的别名版本 Play: https://go.dev/play/p/WHa2CfMO3Lr
func Some ¶ added in v1.2.0
func Some[T comparable](collection []T, subset []T) bool
Some 判断一个切片是否至少包含另一个切片的一个元素(和子集的元素有重叠) @param: collection 大切片 @param: subset 小切片
func SomeBy ¶ added in v1.2.0
SomeBy 切片元素经过函数计算,结果至少有一个true @param: collection 大切片 @param: predicate 计算函数
func Subset ¶ added in v1.2.0
Subset 从指定位置截取切片的指定长度 @param: collection 原切片数据 @param: offset 开始位置,包含 @param: length 截取长度 Play: https://go.dev/play/p/tOQu1GhFcog
func Sum ¶ added in v1.2.0
Sum 对切片元素的值进行累计 Play: https://go.dev/play/p/upfeJVqs4Bt
func SumBy ¶ added in v1.2.0
SumBy 对切片的元素进行计算,计算的结果进行累加 Play: https://go.dev/play/p/Dz_a_7jN_ca
func ToSlicePtr ¶ added in v1.2.0
func ToSlicePtr[T any](collection []T) []*T
ToSlicePtr 返回切片里元素指针的新切片
func Uniq ¶ added in v1.2.0
func Uniq[T comparable](collection []T) []T
Uniq 返回数组的无重复版本,其中只保留每个元素的第一次出现.
func UniqBy ¶ added in v1.2.0
func UniqBy[T any, U comparable](collection []T, iteratee func(item T) U) []T
UniqBy 返回数组的无重复版本,其中只保留每个元素的第一次出现.它接受数组中每个元素调用的iteratee,以生成计算惟一性的条件.
func Without ¶ added in v1.2.0
func Without[T comparable](collection []T, exclude ...T) []T
Without 将给定的排除元素从切片移除
func WithoutEmpty ¶ added in v1.2.0
func WithoutEmpty[T comparable](collection []T) []T
WithoutEmpty 排除切片里面的空数据
Types ¶
type Cloneable ¶ added in v1.2.0
type Cloneable[T any] interface { Clone() T }
Cloneable defines a constraint of types having Clone() T method.
type Complex ¶ added in v1.2.0
type Complex interface { ~complex64 | ~complex128 }