slice

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: MIT Imports: 6 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(slice interface{}, value interface{}) bool

Contain check if the value is in the slice or not

func ConvertSlice

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

ConvertSlice convert original slice to new data type element of slice.

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 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{}

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 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, error)

IntSlice convert param to slice of int.

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 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 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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