Documentation ¶
Index ¶
- func Contains[T comparable](slice []T, item T) bool
- func ContainsBy[T any](slice []T, predicate func(T) bool) bool
- func Diff[T comparable, E any](sources []T, slices []E, f func(v E) T) []T
- func Every[T comparable](collection []T, subset []T) bool
- func EveryBy[T any](collection []T, predicate func(item T) bool) bool
- func Filter[U any](slices []U, predicate func(U) bool) []U
- func FilterIndex[U any](slices []U, predicate func(U, int) bool) []U
- func FilterMap[T any, R any](slices []T, filterTrans func(item T) (bool, R)) []R
- func First[U any](slices []U, predicate func(U) bool) U
- func FlatMap[U any, V any](sources []U, transform func(U) []V) []V
- func FlatMapIndex[U any, V any](sources []U, transform func(U, int) []V) []V
- func Flatten[T any](collection [][]T) []T
- func ForEach[T any](collection []T, iteratee func(T))
- func ForEachIndex[T any](collection []T, iteratee func(T, int))
- func GetAt[E any](slices []E, pos int) E
- func GroupBy[U any, K comparable](slices []U, iteratee func(U) K) map[K][]U
- func GroupFlatMapBy[U any, K comparable, V any](slices []U, trans func(U) (K, []V)) map[K][]V
- func GroupMapBy[U any, K comparable, V any](slices []U, trans func(U) (K, V)) map[K][]V
- func IsEmpty[U any](slices []U) bool
- func IsNotEmpty[U any](slices []U) bool
- func Key[U any, K comparable](sources []U, transform func(u U) K) map[K]U
- func KeyBy[U any, K comparable, V any](sources []U, transform func(u U) (K, V)) map[K]V
- func Make[T any](values ...T) []T
- func Map[U any, V any](sources []U, transfer func(u U) V) []V
- func MapDistinct[U any, V comparable](sources []U, transfer func(u U) V) []V
- func MapIndex[U any, V any](sources []U, transform func(U, int) V) []V
- func Max[T constraints.Ordered](collection []T) T
- func MaxBy[T any](collection []T, comparison func(a T, b T) bool) T
- func Min[T constraints.Ordered](collection []T) T
- func MinBy[T any](collection []T, comparison func(a T, b T) bool) T
- func Nth[T any, N constraints.Integer](collection []T, nth N) (T, error)
- func Reduce[T any, R any](collection []T, accumulator func(R, T, int) R, initial R) R
- func ToFlatMap[U any, K comparable, V any](sources []U, transform func(u U) (K, V)) map[K][]V
- func Uniq[T comparable](slices []T) []T
- func UniqBy[T any, U comparable](slices []T, iteratee func(T) U) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](slice []T, item T) bool
Contains Check item in slice T type
func ContainsBy ¶
ContainsBy returns true if predicate function return true.
func Diff ¶
func Diff[T comparable, E any](sources []T, slices []E, f func(v E) T) []T
Diff Get []T in sources but not in slices Example:
slices.Diff(skus, products, func(p Product) string { return p.TkSku })
func Every ¶
func Every[T comparable](collection []T, subset []T) bool
Every returns true if all elements of a subset are contained into a collection or if the subset is empty.
func EveryBy ¶
EveryBy returns true if the predicate returns true for all of the elements in the collection or if the collection is empty.
func Filter ¶
Filter iterating over elements of a collection, returning an array of all elements predicate returns truthy for.
func FilterIndex ¶
FilterIndex Filter with predicate index Filter handle index
func FilterMap ¶
FilterMap returns a slice which obtained after both filtering and mapping using the given callback function. The callback function should return two values:
- the result of the mapping operation and
- whether the result element should be included or not.
func First ¶
First iterates over elements of collection, returning first element returns truthy for.
func FlatMap ¶
FlatMap manipulates a slice and transforms and flattens it to a slice of another type.
func FlatMapIndex ¶
FlatMapIndex manipulates a slice and transforms and flattens it to a slice of another type. FlatMap handle index
func Flatten ¶
func Flatten[T any](collection [][]T) []T
Flatten returns an array a single level deep. Play: https://go.dev/play/p/rbp9ORaMpjw
func ForEach ¶
func ForEach[T any](collection []T, iteratee func(T))
ForEach iterates over elements of collection and invokes iteratee for each element.
func ForEachIndex ¶
ForEachIndex iterates over elements of collection and invokes iteratee for each element. ForEach handle index
func GroupBy ¶
func GroupBy[U any, K comparable](slices []U, iteratee func(U) K) map[K][]U
GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee.
func GroupFlatMapBy ¶
func GroupFlatMapBy[U any, K comparable, V any](slices []U, trans func(U) (K, []V)) map[K][]V
GroupFlatMapBy returns an object composed of keys generated from the results of running each element of collection through iteratee.
func GroupMapBy ¶
func GroupMapBy[U any, K comparable, V any](slices []U, trans func(U) (K, V)) map[K][]V
GroupMapBy returns an object composed of keys generated from the results of running each element of collection through iteratee.
func Key ¶
func Key[U any, K comparable](sources []U, transform func(u U) K) map[K]U
Key transforms a slice or an array of structs to a map based on a pivot callback Example:
slices.Key(products, func(p Product) int64 { return p.ID })
func KeyBy ¶
func KeyBy[U any, K comparable, V any](sources []U, transform func(u U) (K, V)) map[K]V
KeyBy transforms a slice or an array of structs to a map based on a pivot callback Example:
slices.KeyBy(products, func(p Product) (int64, string) { return p.ID, p.TkSku })
func Map ¶
Map Convert []U to []V with func transform Example:
slices.Map(products, func(p Product) []int64 { return p.ID })
func MapDistinct ¶
func MapDistinct[U any, V comparable](sources []U, transfer func(u U) V) []V
MapDistinct Map and DISTINCT
func MapIndex ¶
MapIndex Convert []U to []V with func transform Map handle index Example:
slices.Map2(products, func(p Product, index int) []int64 { return p.ID })
func Max ¶
func Max[T constraints.Ordered](collection []T) T
Max searches the maximum value of a collection. Returns zero value when collection is empty.
func MaxBy ¶
MaxBy search the maximum value of a collection using the given comparison function. If several values of the collection are equal to the greatest value, returns the first such value. Returns zero value when collection is empty.
func Min ¶
func Min[T constraints.Ordered](collection []T) T
Min search the minimum value of a collection. Returns zero value when collection is empty.
func MinBy ¶
MinBy search the minimum value of a collection using the given comparison function. If several values of the collection are equal to the smallest value, returns the first such value. Returns zero value when collection is empty.
func Nth ¶
func Nth[T any, N constraints.Integer](collection []T, nth N) (T, error)
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 Reduce ¶
Reduce reduces collection to a value which is the accumulated result of running each element in collection through accumulator, where each successive invocation is supplied the return value of the previous.
func ToFlatMap ¶
func ToFlatMap[U any, K comparable, V any](sources []U, transform func(u U) (K, V)) map[K][]V
ToFlatMap convert []U to map[K][]V Example:
collection.MakeAndMergeMap(products, func(p Product) (int64, string) { return p.ID, p.TkSku })
func Uniq ¶
func Uniq[T comparable](slices []T) []T
Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.
func UniqBy ¶
func UniqBy[T any, U comparable](slices []T, iteratee func(T) U) []T
UniqBy returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. It accepts `iteratee` which is invoked for each element in array to generate the criterion by which uniqueness is computed.
Types ¶
This section is empty.