Documentation
¶
Overview ¶
Package dash brings a number of functional utilities to Go.
Index ¶
- func Cycle(slice []T, n uint) []T
- func Drop(slice []T, n int) []T
- func Every(slice []T, pred func(T) bool) bool
- func Filter(slice []T, pred func(T) bool) []T
- func FlatMap(slice []T, f func(T) []M) []M
- func GroupBy(slice []T, f func(T) D) map[D][]T
- func Include(slice []T, e T) bool
- func Intersection(slices ...[]T) (result []T)
- func Keys(m map[K]V) []K
- func Map(slice []T, f func(T) M) []M
- func Merge(maps ...map[K]V) map[K]V
- func MergeWith(f func(v1 V, v2 V) V, maps ...map[K]V) map[K]V
- func None(slice []T, pred func(T) bool) bool
- func ParallelMap(slice []T, f func(T) M) []M
- func ParallelMapN(slice []T, f func(T) M, limit int) []M
- func Partition(slice []T, n int) [][]T
- func PartitionStep(slice []T, n uint, s uint) [][]T
- func Reduce(slice []T, f func(A, T) A, init A) A
- func Reverse(slice []T) []T
- func Rotate(slice []T, n uint) []T
- func Shuffle(slice []T) []T
- func Some(slice []T, pred func(T) bool) bool
- func Take(slice []T, n int) []T
- func Uniq(slice []T) (result []T)
- func Values(m map[K]V) []V
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Drop ¶
Drop returns a new slice containing the remaining values of slice except the first n values.
func Filter ¶
Filter returns a new slice containing all values of slice that the function when function pred returns true.
func FlatMap ¶
FlatMap returns a new slice containing values produced by applying function f to every value in slice, and flattern to a one-dimensional slice.
func GroupBy ¶
func GroupBy[T any, D comparable](slice []T, f func(T) D) map[D][]T
GroupBy returns a map. The keys are the return values of applying f with the values of slice. The values are values of slice which evaluates to it's key.
func Include ¶
func Include[T comparable](slice []T, e T) bool
Include returns true if value e is in slice.
func Intersection ¶
func Intersection[T comparable](slices ...[]T) (result []T)
Intersection returns a single slice containing uniq values among slices.
func Keys ¶
func Keys[K comparable, V any](m map[K]V) []K
Keys returns a slice contains all keys in map m
func Map ¶
Map returns a new slice containing values produced by applying function f to every value in slice.
func Merge ¶
func Merge[K comparable, V any](maps ...map[K]V) map[K]V
Merge maps into one map, uses the value in the latter map.
func MergeWith ¶
func MergeWith[K comparable, V any](f func(v1 V, v2 V) V, maps ...map[K]V) map[K]V
MergeWith returns a new map contains all keys in maps and values by applying function f to all values with the same key
func ParallelMap ¶
ParallelMap works just like Map including the result order, but f is applied in parallel with goroutine. This version creates len(slice) of goroutines, use ParallelMapN if the amount of goroutines created at the same time needs to be limited.
func ParallelMapN ¶
ParallelMapN is a version of ParallelMap, but has a limit of goroutine created at the same time.
func Partition ¶
Partition turn a slice into n-sized(n>0) slices the last k elements are dropped if k<n
func PartitionStep ¶
Partition turn a slice into n-sized(n>0) slices each start with offset s(s>0), right to previous start location the last partition is dropped when size<n
func Reduce ¶
Reduce combines all values of slice into a single value by applying function f with the accumulator value and every value in slice. First iteration of accumulator value is init, the subsequent accumulator value is the return value of f.
func Rotate ¶
Rotate returns a new slice by rotating self so that the element at n is the first element of the new slice.
func Shuffle ¶
func Shuffle[T any](slice []T) []T
Shuffle returns a new slice which containing all the values of slice, but in a random order.
func Uniq ¶
func Uniq[T comparable](slice []T) (result []T)
Uniq returns a new slice containing all uniq values in slice.
func Values ¶
func Values[K comparable, V any](m map[K]V) []V
Keys returns a slice contains all values in map m