slice

package
v0.0.0-...-8aeec60 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ASC  = "asc"
	DESC = "desc"
)

Variables

This section is empty.

Functions

func Chunk

func Chunk[T any](arr []T, size int) [][]T

func Comb

func Comb[T any](arr []T, m int) (r [][]T)

func Copy

func Copy[T any](a []T, l ...int) []T

func Decompress

func Decompress[T any](a [][]T) (r []T)

func DecompressBy

func DecompressBy[T, R any](a [][]T, fn func(T) (R, bool)) (r []R)

func Delete

func Delete[T any](a *[]T, index int)

func Diff

func Diff[T comparable](a []T, b ...[]T) (r []T)

Diff return elements which in a and not in b,...

func DiffByFn

func DiffByFn[T any](a []T, fn func(i, j T) bool, b ...[]T) (r []T)

func DiffNewByFn

func DiffNewByFn[T, V any](a []T, fn func(i, j T) bool, fnV func(T) V, b ...[]T) (r []V)

func Fill

func Fill[T any](start, len int, v T) []T

Fill 用指定值填充一个切片

func Filter

func Filter[T any](arr []T, fn func(T, int) bool) []T

func FilterAndMap

func FilterAndMap[N any, T any](arr []T, fn func(T) (N, bool)) (r []N)

func FilterAndMaps

func FilterAndMaps[N any, T any](arr []T, fn func(int, T) (N, bool)) (r []N)

func FilterAndToMap

func FilterAndToMap[K comparable, V, T any](arr []T, fn func(T, int) (K, V, bool)) map[K]V

func Filters

func Filters[T any](arr []T, fn func(T) bool) []T

func ForEach

func ForEach[T any](a []T, fn func(i int, v T))

func GroupBy

func GroupBy[K comparable, T, V any](a []T, fn func(T) (K, V)) map[K][]V

func IndexOf

func IndexOf[T comparable](a []T, v T) int

func IndexOfBy

func IndexOfBy[T any](a []T, fn func(T) bool) int

func Intersect

func Intersect[T comparable](a []T, b ...[]T) (r []T)

func IntersectByFn

func IntersectByFn[T any](a []T, fn func(i, j T) bool, b ...[]T) (r []T)

func IntersectNewByFn

func IntersectNewByFn[T, V any](a []T, fn func(i, j T) bool, fnV func(T) V, b ...[]T) (r []V)

func IsContained

func IsContained[T comparable](arr []T, a T) bool

func IsContainedByFn

func IsContainedByFn[T any](a []T, e T, fn func(i, j T) bool) bool

func Map

func Map[T, R any](arr []T, fn func(T) R) []R

func Pad

func Pad[T any](a []T, length int, v T) []T

Pad 以指定长度将一个值填充进切片 returns a copy of the array padded to size specified by length with value. If length is positive then the array is padded on the right, if it's negative then on the left. If the absolute value of length is less than or equal to the length of the array then no padding takes place.

func Pagination

func Pagination[T any](arr []T, page, pageSize int) []T

func Pop

func Pop[T any](a *[]T) T

Pop 弹出最后一个元素

func Push

func Push[T any](a *[]T, e ...T)

func Rand

func Rand[T any](a []T) (int, T)

Rand 随机取一个元素

func RandPop

func RandPop[T any](a *[]T) (T, int)

RandPop 随机弹出一个元素并返回那个剩余长度

func Reduce

func Reduce[R, T any](arr []T, fn func(T, R) R, r R) R

func Replace

func Replace[T any](a []T, offset int, replacement []T)

func Reverse

func Reverse[T any](arr []T) []T

func ReversePagination

func ReversePagination[T any](arr []T, page, pageSize int) []T

func ReverseReduce

func ReverseReduce[R, T any](a []T, fn func(T, R) R, r R) R

func ReverseSelf

func ReverseSelf[T any](arr []T) []T

func SearchFirst

func SearchFirst[T any](arr []T, fn func(T) bool) (int, T)

func SearchLast

func SearchLast[T any](arr []T, fn func(T) bool) (int, T)

func Shift

func Shift[T any](a *[]T) (T, int)

Shift 将切片的第一个单元移出并作为结果返回

func Shuffle

func Shuffle[T any](a *[]T)

func SimpleSort

func SimpleSort[T any, O constraints.Ordered](a []T, order string, fn func(t T) O)

func SimpleSorts

func SimpleSorts[T constraints.Ordered](a []T, order string)

func SimpleToMap

func SimpleToMap[K comparable, V any](arr []V, fn func(V) K) map[K]V

func Slice

func Slice[T any](arr []T, offset, length int) (r []T)

func Sort

func Sort[T any](arr []T, fn func(i, j T) bool)

Sort fn i>j desc ↓,i<j asc ↑

func Sorts

func Sorts[T constraints.Ordered](a []T, order string)

func SortsNew

func SortsNew[T constraints.Ordered](a []T, order string) []T

func Splice

func Splice[T any](a *[]T, offset, length int, replacement []T) []T

func StableSort

func StableSort[T any](arr []T, fn func(i, j T) bool)

func ToAnySlice

func ToAnySlice[T any](a []T) []any

func ToMap

func ToMap[K comparable, V, T any](arr []V, fn func(V) (K, T), isCoverPrev bool) map[K]T

func Unique

func Unique[T comparable](a ...[]T) (r []T)

func UniqueByFn

func UniqueByFn[T any](fn func(T, T) bool, a ...[]T) (r []T)

func UniqueNewByFn

func UniqueNewByFn[T, V any](fn func(T, T) bool, fnVal func(T) V, a ...[]T) (r []V)

func Unshift

func Unshift[T any](a *[]T, e ...T)

func Walk

func Walk[T any](arr []T, fn func(*T))

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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