lists

package
v0.0.0-...-a16d59f Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(arr []bool) bool

Any Returns true if all values are true

func Any

func Any(arr []bool) bool

Any Returns true if arr contain any true value

func AsBoolMap

func AsBoolMap[T comparable](vs []T) map[T]bool

AsBoolMap arr -> [value]bool

func AsCountMap

func AsCountMap[T comparable](arr []T) map[T]int

Count arr -> [value]count

func AsIndexMap

func AsIndexMap[T comparable](arr []T) map[T]int

ValueIndex arr -> [value]index

func AsMap

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

AsMap arr -> [key]value

func Concat

func Concat[T any](arrs ...[]T) []T

Concat arrays with copy

func Contains

func Contains[T comparable](arr []T, value T) bool

func Count

func Count[T comparable](arr []T, value T) int

Count returns the count of value in arr

func CountBy

func CountBy[T any](arr []T, fn func(v T, i int) bool) int

CountBy returns the count of value in arr by given function

func CountPages

func CountPages[T constraints.Integer](total, pageSize T) T

func F

func F[T any](arr []T, filter func(v T) bool) []T

Filter

func Filter

func Filter[T any](arr []T, filter func(v T, i int) bool) []T

Filter returns a new slice containing the results of applying fn to each, keep filter(v, i) == true

func GroupBy

func GroupBy[T any, E comparable](arr []T, by func(v T) E) map[E][]T

func GroupByOne

func GroupByOne[T any, E comparable](arr []T, keepFirst bool, by func(v T) E) map[E]T

GroupByOne group by one value

func Index

func Index[T comparable](arr []T, value T) int

Index returns the index of the first instance of value in arr, or -1 if value is not present in arr.

func IndexBy

func IndexBy[T any](arr []T, fn func(v T, i int) bool) int

func Int64s2Strs

func Int64s2Strs(arr []int64) []string

func Intersection

func Intersection[T comparable](a, b []T) []T

func M

func M[T any, V any](arr []T, fn func(v T) V) []V

Map

func Map

func Map[T any, V any](arr []T, fn func(v T, i int) V) []V

Map returns a new slice containing the results of applying fn to each

func Paging

func Paging[T any](page []T, pageSize int) [][]T

func Partition

func Partition[T any](arr []T, n int) [][]T

func R

func R[T any, V any](arr []T, fn func(v T, result V) V, result V) V

Reduce

func Reduce

func Reduce[T any, V any](arr []T, fn func(v T, i int, result V) V, result V) V

Reduce returns a new slice containing the results of applying fn to each

func Reindex

func Reindex[T any](arr []T, indexes []int)

Reindex 按indexes设置索引

func Remove

func Remove[T comparable](list []T, t T) []T

Remove removes the first instance of t from list

func RemoveAll

func RemoveAll[T comparable](list []T, t T) []T

RemoveAll removes all instances of t from list

func Sample

func Sample[T any](arr []T, n int) []T

func Shuffle

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

func Sort

func Sort(arr any, less func(i, j int) []int)

Sort sorts the slice according to the fileds function. less: return comparion result of fields(like sql order by), order by id,name,age: [0,-1,1]

func Strs2Int64s

func Strs2Int64s(arr []string) ([]int64, error)

func Subtract

func Subtract[T comparable](a []T, b []T) []T

func Union

func Union[T comparable](vs ...[]T) []T

func Unique

func Unique[T comparable](vs []T) []T

func Unzip

func Unzip[T any](a [][2]T) ([]T, []T)

func Zip

func Zip[T any](a []T, b []T) [][2]T

Types

This section is empty.

Jump to

Keyboard shortcuts

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