Documentation
¶
Overview ¶
Package slice implements some functions to manipulate slice.
Index ¶
- func Chunk(slice []interface{}, size int) [][]interface{}
- func Contain(iterableType interface{}, value interface{}) bool
- func ConvertSlice(originalSlice interface{}, newSliceType reflect.Type) interface{}
- func Count(slice, function interface{}) int
- func DeleteByIndex(slice interface{}, start int, end ...int) (interface{}, error)
- func Difference(slice1, slice2 interface{}) interface{}
- func Drop(slice interface{}, n int) interface{}
- func Every(slice, function interface{}) bool
- func Filter(slice, function interface{}) interface{}
- func Find(slice, function interface{}) (interface{}, bool)
- func FlattenDeep(slice interface{}) interface{}
- func ForEach(slice, function interface{})
- func GroupBy(slice, function interface{}) (interface{}, interface{})
- func InsertByIndex(slice interface{}, index int, value interface{}) (interface{}, error)
- func IntSlice(slice interface{}) []int
- func InterfaceSlice(slice interface{}) []interface{}
- func Intersection(slices ...interface{}) interface{}
- func Map(slice, function interface{}) interface{}
- func None(slice, function interface{}) bool
- func Reduce(slice, function, zero interface{}) interface{}
- func ReverseSlice(slice interface{})
- func Shuffle(slice interface{}) interface{}
- func Some(slice, function interface{}) bool
- func SortByField(slice interface{}, field string, sortType ...string) error
- func StringSlice(slice interface{}) []string
- func Union(slices ...interface{}) interface{}
- func Unique(slice interface{}) interface{}
- func UpdateByIndex(slice interface{}, index int, value interface{}) (interface{}, error)
- func Without(slice interface{}, values ...interface{}) interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chunk ¶
func Chunk(slice []interface{}, size int) [][]interface{}
Chunk creates an slice of elements split into groups the length of `size`.
func Contain ¶
func Contain(iterableType interface{}, value interface{}) bool
Contain check if the value is in the iterable type or not
func ConvertSlice ¶
ConvertSlice convert original slice to new data type element of slice.
func Count ¶ added in v1.1.9
func Count(slice, function interface{}) int
Count iterates over elements of slice, returns a count of all matched elements The function signature should be func(index int, value interface{}) bool .
func DeleteByIndex ¶
DeleteByIndex delete the element of slice from start index to end index - 1. Delete i: s = append(s[:i], s[i+1:]...) Delete i to j: s = append(s[:i], s[j:]...)
func Difference ¶
func Difference(slice1, slice2 interface{}) interface{}
Difference creates an slice of whose element not included in the other given slice
func Drop ¶ added in v1.1.5
func Drop(slice interface{}, n int) interface{}
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 Every ¶ added in v1.0.6
func Every(slice, function interface{}) bool
Every return true if all of the values in the slice pass the predicate function. The function signature should be func(index int, value interface{}) bool .
func Filter ¶
func Filter(slice, function interface{}) interface{}
Filter iterates over elements of slice, returning an slice of all elements `signature` returns truthy for. The function signature should be func(index int, value interface{}) bool .
func Find ¶ added in v1.0.6
func Find(slice, function interface{}) (interface{}, bool)
Find iterates over elements of slice, returning the first one that passes a truth test on function. The function signature should be func(index int, value interface{}) bool .
func FlattenDeep ¶ added in v1.1.5
func FlattenDeep(slice interface{}) interface{}
FlattenDeep flattens slice recursive
func ForEach ¶ added in v1.1.8
func ForEach(slice, function interface{})
ForEach iterates over elements of slice and invokes function for each element The function signature should be func(index int, value interface{}).
func GroupBy ¶ added in v1.1.6
func GroupBy(slice, function interface{}) (interface{}, interface{})
GroupBy iterate over elements of the slice, each element will be group by criteria, returns two slices The function signature should be func(index int, value interface{}) bool .
func InsertByIndex ¶
InsertByIndex insert the element into slice at index. Insert value: s = append(s[:i], append([]T{x}, s[i:]...)...) Insert slice: a = append(a[:i], append(b, a[i:]...)...)
func InterfaceSlice ¶
func InterfaceSlice(slice interface{}) []interface{}
InterfaceSlice convert param to slice of interface.
func Intersection ¶ added in v1.1.0
func Intersection(slices ...interface{}) interface{}
Intersection creates a slice of unique values that included by all slices.
func Map ¶
func Map(slice, function interface{}) interface{}
Map creates an slice of values by running each element of `slice` thru `function`. The function signature should be func(index int, value interface{}) interface{}.
func None ¶ added in v1.1.8
func None(slice, function interface{}) bool
None return true if all the values in the slice mismatch the criteria The function signature should be func(index int, value interface{}) bool .
func Reduce ¶
func Reduce(slice, function, zero interface{}) interface{}
Reduce creates an slice of values by running each element of `slice` thru `function`. The function signature should be func(index int, value1, value2 interface{}) interface{} .
func ReverseSlice ¶
func ReverseSlice(slice interface{})
ReverseSlice return slice of element order is reversed to the given slice
func Shuffle ¶ added in v1.1.5
func Shuffle(slice interface{}) interface{}
Shuffle creates an slice of shuffled values
func Some ¶ added in v1.0.6
func Some(slice, function interface{}) bool
Some return true if any of the values in the list pass the predicate function. The function signature should be func(index int, value interface{}) bool .
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 ¶
func StringSlice(slice interface{}) []string
StringSlice convert param to slice of string.
func Union ¶ added in v1.1.0
func Union(slices ...interface{}) interface{}
Union creates a slice of unique values, in order, from all given slices. using == for equality comparisons.
func UpdateByIndex ¶
UpdateByIndex update the slice element at index.
Types ¶
This section is empty.