{"modulePath":"github.com/vongoethe/go-utils","version":"v1.0.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package array\n\n## Functions\n\n```go\nfunc AnyIn[T comparable](vals []T, items []T) bool\n```\nAnyIn 判断 vals 中的任意元素是否在 items 中\n\n```go\nfunc BuildMap[T any, M any, K comparable](input []T, mapBuilder func(value T, i int) (K, M)) map[K]M\n```\nBuildMap 遍历 input 数组，使用 mapBuilder 函数（返回值为 Key, Value）创建 map\n\n```go\nfunc Chunks[T any](data []T, size int) [][]T\n```\nChunks 将数组分割成多个指定长度的数组\n\n```go\nfunc ChunksEach[T any](data []T, size int, cb func(items []T))\n```\nChunksEach 将数组分割成多个指定长度的数组，依次执行 cb 函数\n\n```go\nfunc Diff[T comparable](itemsA []T, itemsB []T) []T\n```\nDiff 提取 itemsA 中包含，但是 itemsB 中不存在的元素\n\n```go\nfunc Difference[T comparable](a, b []T) []T\n```\nDifference 取数据 a 和 b 的差集（返回在数据 a 中，但是不在 b 中的元素）\n\n```go\nfunc Distinct[K comparable](input []K) []K\n```\nDistinct remove duplicate elements from array\n\n```go\nfunc DistinctBy[K any, V comparable](input []K, keyFunc func(item K) V) []K\n```\nDistinctBy remove duplicate elements from array, use keyFunc to compare\n\n```go\nfunc Each[T any](data []T, cb func(item T, index int))\n```\nEach 遍历data，依次执行 cb 函数\n\n```go\nfunc Exclude[T comparable](items []T, excepts ...T) []T\n```\nExclude exclude all items match excepts\n\n```go\nfunc Filter[T any](items []T, predicate func(item T, index int) bool) []T\n```\nFilter 字符串数组过滤\n\n```go\nfunc FromMap[T any, K comparable](input map[K]T) []T\n```\nFromMap 从 map 中提取数组\n\n```go\nfunc FromMapKeys[T any, K comparable](input map[K]T) []K\n```\nFromMapKeys 将 map 的 key 转换为数组\n\n```go\nfunc GroupBy[T any, K comparable](data []T, cb func(item T) K) map[K][]T\n```\nGroupBy 按照数组的某个值进行分组\n\n```go\nfunc In[T comparable](val T, items []T) bool\n```\nIn 判断元素是否在数组中\n\n```go\nfunc Intersect[T comparable](arr1 []T, arr2 []T) []T\n```\nIntersect 两个数组取交集\n\n```go\nfunc Map[T any, K any](items []T, mapper func(item T, index int) K) []K\n```\nMap 依次对每一个元素做 mapper 操作\n\n```go\nfunc Reduce[T any, K any](data []K, cb func(carry T, item K) T, initValue T) T\n```\nReduce 对数组执行 reduce 操作\n\n```go\nfunc ReduceWithIndex[T any, K any](data []K, cb func(carry T, item K, index int) T, initValue T) T\n```\nReduceWithIndex 对数组执行 reduce 操作\n\n```go\nfunc Repeat[T any](item T, count int) []T\n```\nRepeat 生成 count 个包含 item 值的数组\n\n```go\nfunc RepeatFunc[T any](fn func() T, count int) []T\n```\nRepeatFunc 重复执行 count 次 fn，返回结果为数组\n\n```go\nfunc Reverse[T any](data []T) []T\n```\nReverse 数组逆序\n\n```go\nfunc Shuffle[T any](data []T) []T\n```\nShuffle 随机打乱数组，使用前请注意需要使用 rand.Seed(time.Now().UnixNano()) 方法来初始化随机数种子\n\n```go\nfunc Sort[T any](data []T, cb func(item1 T, item2 T) bool) []T\n```\nSort 对数组进行排序\n\n```go\nfunc ToMap[T any, K comparable](input []T, keyFunc func(T, int) K) map[K]T\n```\nToMap 将数组转换为 map\n\n```go\nfunc Union[T comparable](itemsA []T, itemsB []T) []T\n```\nUnion 两个字符串数组合并，去重复\n\n```go\nfunc Uniq[K comparable](input []K) []K\n```\nUniq remove duplicate elements from array\n\n```go\nfunc UniqBy[K any, V comparable](input []K, keyFunc func(item K) V) []K\n```\nUniqBy remove duplicate elements from array, use keyFunc to compare\n\n","path":"github.com/vongoethe/go-utils/array","name":"array","synopsis":"","isRedistributable":true}
