Documentation ¶
Index ¶
- func AppendIfAbsent[T comparable](slice []T, item T) []T
- func Chunk[T any](slice []T, size int) [][]T
- func Compact[T comparable](slice []T) []T
- func Concat[T any](slice []T, slices ...[]T) []T
- func Contain[T comparable](slice []T, target T) bool
- func ContainBy[T any](slice []T, predicate func(item T) bool) bool
- func ContainSubSlice[T comparable](slice, subSlice []T) bool
- func Count[T comparable](slice []T, item T) int
- func CountBy[T any](slice []T, predicate func(index int, item T) bool) int
- func DeleteAt[T any](slice []T, start int, end ...int) []T
- func Difference[T comparable](slice, comparedSlice []T) []T
- func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
- func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(item1, item2 T) bool) []T
- func Drop[T any](slice []T, n int) []T
- func DropRight[T any](slice []T, n int) []T
- func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T
- func DropWhile[T any](slice []T, predicate func(item T) bool) []T
- func Equal[T comparable](slice1, slice2 []T) bool
- func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
- func Every[T any](slice []T, predicate func(index int, item T) bool) bool
- func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
- func FilterMap[T any, U any](slice []T, iteratee func(index int, item T) (U, bool)) []U
- func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
- func FindBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool)
- func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
- func FindLastBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool)
- func FlatMap[T any, U any](slice []T, iteratee func(index int, item T) []U) []U
- func Flatten(slice any) any
- func FlattenDeep(slice any) any
- func ForEach[T any](slice []T, iteratee func(index int, item T))
- func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool)
- func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
- func GroupWith[T any, U comparable](slice []T, iteratee func(item T) U) map[U][]T
- func IndexOf[T comparable](arr []T, val T) int
- func InsertAt[T any](slice []T, index int, value any) []T
- func IntSlice(slice any) []int
- func InterfaceSlice(slice any) []any
- func Intersection[T comparable](slices ...[]T) []T
- func IsAscending[T constraints.Ordered](slice []T) bool
- func IsDescending[T constraints.Ordered](slice []T) bool
- func IsSorted[T constraints.Ordered](slice []T) bool
- func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
- func Join[T any](s []T, separator string) string
- func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
- func LastIndexOf[T comparable](slice []T, item T) int
- func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
- func Merge[T any](slices ...[]T) []T
- func None[T any](slice []T, predicate func(index int, item T) bool) bool
- func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
- func ReduceBy[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
- func ReduceRight[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
- func Repeat[T any](item T, n int) []T
- func Replace[T comparable](slice []T, old T, new T, n int) []T
- func ReplaceAll[T comparable](slice []T, old T, new T) []T
- func Reverse[T any](slice []T)
- func Shuffle[T any](slice []T) []T
- func Some[T any](slice []T, predicate func(index int, item T) bool) bool
- func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
- func SortBy[T any](slice []T, less func(a, b T) bool)
- func SortByField(slice any, field string, sortType ...string) error
- func StringSlice(slice any) []string
- func SymmetricDifference[T comparable](slices ...[]T) []T
- func ToSlice[T any](items ...T) []T
- func ToSlicePointer[T any](items ...T) []*T
- func Union[T comparable](slices ...[]T) []T
- func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
- func Unique[T comparable](slice []T) []T
- func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
- func UpdateAt[T any](slice []T, index int, value T) []T
- func Without[T comparable](slice []T, items ...T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendIfAbsent ¶
func AppendIfAbsent[T comparable](slice []T, item T) []T
AppendIfAbsent only absent append the item.
func Compact ¶
func Compact[T comparable](slice []T) []T
Compact creates an slice with all falsey values removed. The values false, nil, 0, and "" are falsey.
func Concat ¶
func Concat[T any](slice []T, slices ...[]T) []T
Concat creates a new slice concatenating slice with any additional slices.
func Contain ¶
func Contain[T comparable](slice []T, target T) bool
Contain check if the target value is in the slice or not.
func ContainSubSlice ¶
func ContainSubSlice[T comparable](slice, subSlice []T) bool
ContainSubSlice check if the slice contain a given subslice or not.
func Count ¶
func Count[T comparable](slice []T, item T) int
Count returns the number of occurrences of the given item in the slice.
func CountBy ¶
CountBy iterates over elements of slice with predicate function, returns the number of all matched elements.
func DeleteAt ¶
DeleteAt delete the element of slice from start index to end index - 1. Play: https://go.dev/play/p/pJ-d6MUWcvK
func Difference ¶
func Difference[T comparable](slice, comparedSlice []T) []T
Difference creates an slice of whose element in slice but not in comparedSlice.
func DifferenceBy ¶
func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
DifferenceBy it accepts iteratee which is invoked for each element of slice and values to generate the criterion by which they're compared.
func DifferenceWith ¶
DifferenceWith accepts comparator which is invoked to compare elements of slice to values. The order and references of result values are determined by the first slice. The comparator is invoked with two arguments: (arrVal, othVal).
func Drop ¶
Drop drop n elements from the start of a slice. Play: https://go.dev/play/p/jnPO2yQsT8H
func DropRight ¶
DropRight drop n elements from the end of a slice. Play: https://go.dev/play/p/8bcXvywZezG
func DropRightWhile ¶
DropRightWhile drop n elements from the end of a slice while predicate function returns true. Play: https://go.dev/play/p/6wyK3zMY56e
func DropWhile ¶
DropWhile drop n elements from the start of a slice while predicate function returns true. Play: https://go.dev/play/p/4rt252UV_qs
func Equal ¶
func Equal[T comparable](slice1, slice2 []T) bool
Equal checks if two slices are equal: the same length and all elements' order and value are equal.
func Filter ¶
Filter iterates over elements of slice, returning an slice of all elements pass the predicate function.
func FilterMap ¶
FilterMap returns a slice which apply both filtering and mapping to the given slice. iteratee callback function should returntwo values: 1, mapping result. 2, whether the result element should be included or not
func Find ¶
Find iterates over elements of slice, returning the first one that passes a truth test on predicate function. If return T is nil then no items matched the predicate func.
func FindBy ¶
FindBy iterates over elements of slice, returning the first one that passes a truth test on predicate function. If return T is nil or zero value then no items matched the predicate func. In contrast to Find or FindLast, its return value no longer requires dereferencing
func FindLast ¶
FindLast iterates over elements of slice from end to begin, return the first one that passes a truth test on predicate function. If return T is nil then no items matched the predicate func.
func FindLastBy ¶
FindLastBy iterates over elements of slice, returning the last one that passes a truth test on predicate function. If return T is nil or zero value then no items matched the predicate func. In contrast to Find or FindLast, its return value no longer requires dereferencing
func FlatMap ¶
FlatMap manipulates a slice and transforms and flattens it to a slice of another type.
func ForEachWithBreak ¶
ForEachWithBreak iterates over elements of slice and invokes function for each element, when iteratee return false, will break the for each loop.
func GroupBy ¶
GroupBy iterate over elements of the slice, each element will be group by criteria, returns two slices.
func GroupWith ¶
func GroupWith[T any, U comparable](slice []T, iteratee func(item T) U) map[U][]T
GroupWith return a map composed of keys generated from the resultults of running each element of slice thru iteratee.
func IndexOf ¶
func IndexOf[T comparable](arr []T, val T) int
IndexOf returns the index at which the first occurrence of an item is found in a slice or return -1 if the item cannot be found.
func InsertAt ¶
InsertAt insert the value or other slice into slice at index. Play: https://go.dev/play/p/hMLNxPEGJVE
func IntSlice ¶
IntSlice convert param to slice of int. This function is deprecated, use generics feature of go1.18+ for replacement. Play: https://go.dev/play/p/UQDj-on9TGN
func InterfaceSlice ¶
InterfaceSlice convert param to slice of interface. This function is deprecated, use generics feature of go1.18+ for replacement. Play: https://go.dev/play/p/FdQXF0Vvqs-
func Intersection ¶
func Intersection[T comparable](slices ...[]T) []T
Intersection creates a slice of unique elements that included by all slices. Play: https://go.dev/play/p/anJXfB5wq_t
func IsAscending ¶
func IsAscending[T constraints.Ordered](slice []T) bool
IsAscending checks if a slice is ascending order.
func IsDescending ¶
func IsDescending[T constraints.Ordered](slice []T) bool
IsDescending checks if a slice is descending order.
func IsSorted ¶
func IsSorted[T constraints.Ordered](slice []T) bool
IsSorted checks if a slice is sorted(ascending or descending).
func IsSortedByKey ¶
func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
IsSortedByKey checks if a slice is sorted by iteratee function.
func KeyBy ¶
func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
KeyBy converts a slice to a map based on a callback function.
func LastIndexOf ¶
func LastIndexOf[T comparable](slice []T, item T) int
LastIndexOf returns the index at which the last occurrence of the item is found in a slice or return -1 if the then cannot be found.
func Merge ¶
func Merge[T any](slices ...[]T) []T
Merge all given slices into one slice. Play: https://go.dev/play/p/lbjFp784r9N
func Reduce ¶
Reduce creates an slice of values by running each element of slice thru iteratee function.
func ReduceBy ¶
ReduceBy produces a value from slice by accumulating the result of each element as passed through the reducer function.
func ReduceRight ¶
ReduceRight is like ReduceBy, but it iterates over elements of slice from right to left.
func Repeat ¶
Repeat creates a slice with length n whose elements are param `item`. Play: https://go.dev/play/p/1CbOmtgILUU
func Replace ¶
func Replace[T comparable](slice []T, old T, new T, n int) []T
Replace returns a copy of the slice with the first n non-overlapping instances of old replaced by new. Play: https://go.dev/play/p/P5mZp7IhOFo
func ReplaceAll ¶
func ReplaceAll[T comparable](slice []T, old T, new T) []T
ReplaceAll returns a copy of the slice with all non-overlapping instances of old replaced by new. Play: https://go.dev/play/p/CzqXMsuYUrx
func Reverse ¶
func Reverse[T any](slice []T)
Reverse return slice of element order is reversed to the given slice. Play: https://go.dev/play/p/8uI8f1lwNrQ
func Sort ¶
func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
Sort sorts a slice of any ordered type(number or string), use quick sort algrithm. default sort order is ascending (asc), if want descending order, set param `sortOrder` to `desc`.
func SortBy ¶
SortBy sorts the slice in ascending order as determined by the less function. This sort is not guaranteed to be stable.
func SortByField ¶
SortByField return sorted slice by field slice element should be struct, field type should be int, uint, string, or bool default sortType is ascending (asc), if descending order, set sortType to desc This function is deprecated, use Sort and SortBy for replacement.
func StringSlice ¶
StringSlice convert param to slice of string. This function is deprecated, use generics feature of go1.18+ for replacement. Play: https://go.dev/play/p/W0TZDWCPFcI
func SymmetricDifference ¶
func SymmetricDifference[T comparable](slices ...[]T) []T
SymmetricDifference oppoiste operation of intersection function. Play: https://go.dev/play/p/h42nJX5xMln
func ToSlice ¶
func ToSlice[T any](items ...T) []T
ToSlice returns a slices of a variable parameter transformation.
func ToSlicePointer ¶
func ToSlicePointer[T any](items ...T) []*T
ToSlicePointer returns a pointer to the slices of a variable parameter transformation.
func Union ¶
func Union[T comparable](slices ...[]T) []T
Union creates a slice of unique elements, in order, from all given slices. Play: https://go.dev/play/p/hfXV1iRIZOf
func UnionBy ¶
func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
UnionBy is like Union, what's more it accepts iteratee which is invoked for each element of each slice. Play: https://go.dev/play/p/HGKHfxKQsFi
func Unique ¶
func Unique[T comparable](slice []T) []T
Unique remove duplicate elements in slice. Play: https://go.dev/play/p/AXw0R3ZTE6a
func UniqueBy ¶
func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
UniqueBy call iteratee func with every item of slice, then remove duplicated. Play: https://go.dev/play/p/UR323iZLDpv
func UpdateAt ¶
UpdateAt update the slice element at index. Play: https://go.dev/play/p/f3mh2KloWVm
func Without ¶
func Without[T comparable](slice []T, items ...T) []T
Without creates a slice excluding all given items.
Types ¶
This section is empty.