slice

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 7 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 AppendIfAbsent added in v1.3.1

func AppendIfAbsent(slice interface{}, value interface{}) interface{}

AppendIfAbsent only absent append the value

func Chunk

func Chunk(slice []interface{}, size int) [][]interface{}

Chunk creates an slice of elements split into groups the length of `size`.

func Compact added in v1.2.2

func Compact(slice interface{}) interface{}

Compact creates an slice with all falsey values removed. The values false, nil, 0, and "" are falsey

func Concat added in v1.2.2

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

Concat creates a new slice concatenating slice with any additional slices and/or values.

func Contain

func Contain(iterableType interface{}, value interface{}) bool

Contain check if the value is in the iterable type or not

func ContainSubSlice added in v1.1.10

func ContainSubSlice(slice interface{}, subslice interface{}) bool

ContainSubSlice check if the slice contain subslice or not

func Count added in v1.1.9

func Count(slice, iteratee interface{}) int

Count iterates over elements of slice, returns a count of all matched elements The iteratee 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 in slice1, not in slice2

func DifferenceBy added in v1.2.2

func DifferenceBy(slice interface{}, comparedSlice interface{}, iteratee interface{}) interface{}

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, the iteratee function signature should be func(index int, value interface{}) interface{}.

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 Equal added in v1.3.0

func Equal(slice1, slice2 interface{}) bool

Equal checks if two slices are equal: the same length and all elements' order and value are equal

func EqualWith added in v1.3.0

func EqualWith(slice1, slice2 interface{}, comparator interface{}) bool

EqualWith checks if two slices are equal with comparator func

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 iteratee function signature should be func(index int, value interface{}) bool .

func Filter

func Filter(slice, iteratee interface{}) interface{}

Filter iterates over elements of slice, returning an slice of all elements `signature` returns truthy for. The iteratee function signature should be func(index int, value interface{}) bool .

func Find added in v1.0.6

func Find(slice, predicate interface{}) (interface{}, bool)

Find iterates over elements of slice, returning the first one that passes a truth test on function. The predicate function signature should be func(index int, value interface{}) bool .

func FindLast added in v1.2.3

func FindLast(slice, predicate interface{}) (interface{}, bool)

FindLast iterates over elements of slice from end to begin, 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, iteratee interface{})

ForEach iterates over elements of slice and invokes function for each element The iteratee function signature should be func(index int, value interface{}).

func GroupBy added in v1.1.6

func GroupBy(slice, iteratee interface{}) (interface{}, interface{})

GroupBy iterate over elements of the slice, each element will be group by criteria, returns two slices The iteratee function signature should be func(index int, value interface{}) bool .

func IndexOf added in v1.3.0

func IndexOf(slice, value interface{}) int

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 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 LastIndexOf added in v1.3.0

func LastIndexOf(slice, value interface{}) int

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 Map

func Map(slice, iteratee interface{}) interface{}

Map creates an slice of values by running each element of `slice` thru `function`. The iteratee function signature should be func(index int, value interface{}) interface{}.

func None added in v1.1.8

func None(slice, iteratee interface{}) bool

None return true if all the values in the slice mismatch the criteria The iteratee 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, iteratee interface{}) bool

Some return true if any of the values in the list pass the predicate function. The iteratee 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 ToSlice added in v1.3.1

func ToSlice(value ...interface{}) interface{}

ToSlice returns a slices of a variable parameter transformation

func ToSlicePointer added in v1.3.1

func ToSlicePointer(value ...interface{}) []*interface{}

ToSlicePointer returns a pointer to the slices of a variable parameter transformation

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 UniqueBy added in v1.3.0

func UniqueBy(slice, iteratee interface{}) interface{}

UniqueBy call iteratee func with every item of slice, then remove duplicated. The iteratee function signature should be func(value interface{}) interface{}.

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