slice

package
v1.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 8 Imported by: 2

Documentation

Overview

Package slice implements some functions to manipulate slice.

Index

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

func ConvertSlice(originalSlice interface{}, newSliceType reflect.Type) interface{}

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

func DeleteByIndex(slice interface{}, start int, end ...int) (interface{}, error)

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

func InsertByIndex(slice interface{}, index int, value interface{}) (interface{}, error)

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 IntSlice

func IntSlice(slice interface{}) []int

IntSlice convert param to slice of int.

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

func SortByField(slice interface{}, field string, sortType ...string) error

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 Unique

func Unique(slice interface{}) interface{}

Unique remove duplicate elements in slice.

func UpdateByIndex

func UpdateByIndex(slice interface{}, index int, value interface{}) (interface{}, error)

UpdateByIndex update the slice element at index.

func Without added in v1.1.0

func Without(slice interface{}, values ...interface{}) interface{}

Without creates a slice excluding all given values

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL