Documentation
¶
Overview ¶
Package slices provides generic operations on slices because we've got better things to do than write for-loops over and over.
Index ¶
- func Contains[V comparable](src []V, wanted V) bool
- func ContainsAll[V any](src []V, selector func(V) bool) bool
- func ContainsAllErr[V any](src []V, selector func(V) (bool, error)) (bool, error)
- func ContainsAny[V any](src []V, selector func(V) bool) bool
- func ContainsAnyErr[V any](src []V, selector func(V) (bool, error)) (bool, error)
- func First[V any](src []V, selector func(V) bool) V
- func FirstErr[V any](src []V, selector func(V) (bool, error)) (V, error)
- 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 Index[V comparable](src []V, wanted V) int
- func IndexOf[V any](src []V, selector func(V) bool) int
- func IndexOfErr[V any](src []V, selector func(V) (bool, error)) (int, 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 Contains ¶ added in v0.4.3
func Contains[V comparable](src []V, wanted V) bool
Contains returns true when the slice contains the wanted value.
func ContainsAll ¶ added in v0.4.3
ContainsAll returns true when the selector returns true for all values in the slice.
func ContainsAllErr ¶ added in v0.4.3
ContainsAllErr allows the selector to return an error which is then returned to the caller.
func ContainsAny ¶ added in v0.4.3
ContainsAny returns true when the slice contains a value for which the selector returns true.
func ContainsAnyErr ¶ added in v0.4.3
ContainsAnyErr allows the selector to return an error which is then returned to the caller.
func First ¶ added in v0.4.3
First returns the first value in the slice where the selector returned true, or the zero value of V if the selector never returns true.
func FirstErr ¶ added in v0.4.3
FirstErr allows the selector to return an error which is then returned to the caller.
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 Index ¶ added in v0.4.3
func Index[V comparable](src []V, wanted V) int
Index returns the first index in the slice that contains the wanted value, or -1 if not found.
func IndexOf ¶ added in v0.4.3
IndexOf returns the first index in the slice where the selector returned true, or -1 if not found.
func IndexOfErr ¶ added in v0.4.3
IndexOfErr allows the selector to return an error which is then returned to the caller.
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.
func Select ¶ added in v0.4.1
Select returns a slice with all values where the selector returned true.
Types ¶
This section is empty.