Documentation ¶
Index ¶
- func AnyIn[T comparable](vals []T, items []T) bool
- func BuildMap[T any, M any, K comparable](input []T, mapBuilder func(value T, i int) (K, M)) map[K]M
- func Chunks[T any](data []T, size int) [][]T
- func ChunksEach[T any](data []T, size int, cb func(items []T))
- func Diff[T comparable](itemsA []T, itemsB []T) []T
- func Difference[T comparable](a, b []T) []T
- func Distinct[K comparable](input []K) []K
- func DistinctBy[K any, V comparable](input []K, keyFunc func(item K) V) []K
- func Each[T any](data []T, cb func(item T, index int))
- func Exclude[T comparable](items []T, excepts ...T) []T
- func Filter[T any](items []T, predicate func(item T, index int) bool) []T
- func FromMap[T any, K comparable](input map[K]T) []T
- func FromMapKeys[T any, K comparable](input map[K]T) []K
- func GroupBy[T any, K comparable](data []T, cb func(item T) K) map[K][]T
- func In[T comparable](val T, items []T) bool
- func Intersect[T comparable](arr1 []T, arr2 []T) []T
- func Map[T any, K any](items []T, mapper func(item T, index int) K) []K
- func Reduce[T any, K any](data []K, cb func(carry T, item K) T, initValue T) T
- func ReduceWithIndex[T any, K any](data []K, cb func(carry T, item K, index int) T, initValue T) T
- func Repeat[T any](item T, count int) []T
- func RepeatFunc[T any](fn func() T, count int) []T
- func Reverse[T any](data []T) []T
- func Shuffle[T any](data []T) []T
- func Sort[T any](data []T, cb func(item1 T, item2 T) bool) []T
- func ToMap[T any, K comparable](input []T, keyFunc func(T, int) K) map[K]T
- func Union[T comparable](itemsA []T, itemsB []T) []T
- func Uniq[K comparable](input []K) []K
- func UniqBy[K any, V comparable](input []K, keyFunc func(item K) V) []K
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildMap ¶
func BuildMap[T any, M any, K comparable](input []T, mapBuilder func(value T, i int) (K, M)) map[K]M
BuildMap 遍历 input 数组,使用 mapBuilder 函数(返回值为 Key, Value)创建 map
func ChunksEach ¶ added in v1.0.2
ChunksEach 将数组分割成多个指定长度的数组,依次执行 cb 函数
func Diff ¶
func Diff[T comparable](itemsA []T, itemsB []T) []T
Diff 提取 itemsA 中包含,但是 itemsB 中不存在的元素
func Difference ¶
func Difference[T comparable](a, b []T) []T
Difference 取数据 a 和 b 的差集(返回在数据 a 中,但是不在 b 中的元素)
func Distinct ¶
func Distinct[K comparable](input []K) []K
Distinct remove duplicate elements from array
func DistinctBy ¶ added in v1.0.3
func DistinctBy[K any, V comparable](input []K, keyFunc func(item K) V) []K
DistinctBy remove duplicate elements from array, use keyFunc to compare
func Exclude ¶
func Exclude[T comparable](items []T, excepts ...T) []T
Exclude exclude all items match excepts
func FromMapKeys ¶
func FromMapKeys[T any, K comparable](input map[K]T) []K
FromMapKeys 将 map 的 key 转换为数组
func GroupBy ¶
func GroupBy[T any, K comparable](data []T, cb func(item T) K) map[K][]T
GroupBy 按照数组的某个值进行分组
func ReduceWithIndex ¶ added in v1.0.1
ReduceWithIndex 对数组执行 reduce 操作
func RepeatFunc ¶
RepeatFunc 重复执行 count 次 fn,返回结果为数组
func Shuffle ¶ added in v1.0.2
func Shuffle[T any](data []T) []T
Shuffle 随机打乱数组,使用前请注意需要使用 rand.Seed(time.Now().UnixNano()) 方法来初始化随机数种子
func ToMap ¶
func ToMap[T any, K comparable](input []T, keyFunc func(T, int) K) map[K]T
ToMap 将数组转换为 map
func Uniq ¶ added in v1.0.2
func Uniq[K comparable](input []K) []K
Uniq remove duplicate elements from array
func UniqBy ¶ added in v1.0.3
func UniqBy[K any, V comparable](input []K, keyFunc func(item K) V) []K
UniqBy remove duplicate elements from array, use keyFunc to compare
Types ¶
This section is empty.