Documentation
¶
Overview ¶
Package slice implements some functions to manipulate slice.
Index ¶
- func Chunk[T any](slice []T, size int) [][]T
- func Compact[T any](slice []T) []T
- func Concat[T any](slice []T, values ...[]T) []T
- func Contain[T any](slice []T, value T) bool
- func ContainSubSlice[T any](slice, subslice []T) bool
- func Count[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 any](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
- func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
- func Drop[T any](slice []T, n int) []T
- 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 Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
- func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
- func FlattenDeep(slice any) any
- func ForEach[T any](slice []T, iteratee func(index int, item T))
- 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(T) U) map[U][]T
- func IndexOf[T any](slice []T, value 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 any](slices ...[]T) []T
- func LastIndexOf[T any](slice []T, value T) int
- func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
- 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 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 SortByField(slice any, field string, sortType ...string) error
- func StringSlice(slice any) []string
- func SymmetricDifference[T any](slices ...[]T) []T
- func Union[T any](slices ...[]T) []T
- func Unique[T any](slice []T) []T
- func UpdateAt[T any](slice []T, index int, value T) []T
- func Without[T any](slice []T, values ...T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compact ¶
func Compact[T any](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, values ...[]T) []T
Concat creates a new slice concatenating slice with any additional slices and/or values.
func ContainSubSlice ¶
ContainSubSlice check if the slice contain subslice or not
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 ¶
DifferenceBy it accepts iteratee which is invoked for each element of slice and values to generate the criterion by which they're compared. like lodash.js differenceBy: https://lodash.com/docs/4.17.15#differenceBy,
func DifferenceWith ¶
func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
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 creates a slice with `n` elements dropped from the beginning when n > 0, or `n` elements dropped from the ending when n < 0
func Filter ¶
Filter iterates over elements of slice, returning an slice of all elements pass the predicate function
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 FindLast ¶
FindLast iterates over elements of slice from end to begin, 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 GroupBy ¶
GroupBy iterate over elements of the slice, each element will be group by criteria, returns two slices
func GroupWith ¶ added in v2.0.1
func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T
GroupWith return a map composed of keys generated from the results of running each element of slice thru iteratee.
func IndexOf ¶ added in v2.0.7
IndexOf returns the index at which the first occurrence of a value is found in a slice or return -1 if the value cannot be found.
func InterfaceSlice ¶
InterfaceSlice convert param to slice of interface.
func Intersection ¶
func Intersection[T any](slices ...[]T) []T
Intersection creates a slice of unique values that included by all slices.
func LastIndexOf ¶ added in v2.0.7
LastIndexOf returns the index at which the last occurrence of a value is found in a slice or return -1 if the value cannot be found.
func Reduce ¶
Reduce creates an slice of values by running each element of slice thru iteratee function.
func Reverse ¶
func Reverse[T any](slice []T)
Reverse return slice of element order is reversed to the given slice
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
func StringSlice ¶
StringSlice convert param to slice of string.
func SymmetricDifference ¶ added in v2.0.3
func SymmetricDifference[T any](slices ...[]T) []T
SymmetricDifference oppoiste operation of intersection function
func Union ¶
func Union[T any](slices ...[]T) []T
Union creates a slice of unique values, in order, from all given slices. using == for equality comparisons.
Types ¶
This section is empty.