Documentation
¶
Overview ¶
Package slices provides generic operations on slices, including map, reduce, split, and group by.
Index ¶
- func GroupBy[K comparable, V any](src []V, keyFn func(V) K) map[K][]V
- func GroupByErr[K comparable, V any](src []V, keyFn func(V) (K, error)) (map[K][]V, error)
- func Map[A any, B any](src []A, mapper func(A) B) []B
- func MapErr[A any, B any](src []A, mapper func(A) (B, error)) ([]B, error)
- func Reduce[V any, A any](values []V, acc A, reducer func(acc A, val V) A) A
- func ReduceErr[V any, A any](values []V, acc A, reducer func(acc A, val V) (A, error)) (A, error)
- func Select[V any](src []V, selector func(V) bool) []V
- func SelectErr[V any](src []V, selector func(V) (bool, error)) ([]V, error)
- func Split[X any](src []X, partLen int) [][]X
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GroupBy ¶ added in v0.2.4
func GroupBy[K comparable, V any](src []V, keyFn func(V) K) map[K][]V
GroupBy indexes the given values by the result of the key function.
func GroupByErr ¶ added in v0.2.7
func GroupByErr[K comparable, V any](src []V, keyFn func(V) (K, error)) (map[K][]V, error)
GroupByErr allows the key function to fail and returns the failing error.
func MapErr ¶ added in v0.2.0
MapErr allows the mapper function to fail and returns the failing error.
func Reduce ¶ added in v0.2.0
Reduce a slice to a single value given an initial value and a reducer function.
func ReduceErr ¶ added in v0.2.0
ReduceErr allows the reducer function to fail and returns the failing error.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.