Documentation
¶
Overview ¶
Package slice implements some functions to manipulate slice.
Index ¶
- func Chunk(slice []interface{}, size int) [][]interface{}
- func Contain(slice interface{}, value interface{}) bool
- func ConvertSlice(originalSlice interface{}, newSliceType reflect.Type) interface{}
- func DeleteByIndex(slice interface{}, start int, end ...int) (interface{}, error)
- func Difference(slice1, slice2 interface{}) interface{}
- func Filter(slice, function interface{}) interface{}
- func InsertByIndex(slice interface{}, index int, value interface{}) (interface{}, error)
- func IntSlice(slice interface{}) ([]int, error)
- func InterfaceSlice(slice interface{}) []interface{}
- func Map(slice, function interface{}) interface{}
- func Reduce(slice, function, zero interface{}) interface{}
- func ReverseSlice(slice interface{})
- func SortByField(slice interface{}, field string, sortType ...string) error
- func StringSlice(slice interface{}) []string
- func Unique(slice interface{}) interface{}
- func UpdateByIndex(slice interface{}, index int, value interface{}) (interface{}, error)
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(slice interface{}, value interface{}) bool
Contain check if the value is in the slice or not
func ConvertSlice ¶
ConvertSlice convert original slice to new data type element of slice.
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 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 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 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 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 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 UpdateByIndex ¶
UpdateByIndex update the slice element at index.
Types ¶
This section is empty.