Documentation
¶
Index ¶
- func Chunk[X any](src []X, numParts int) [][]X
- 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 Chunk ¶ added in v0.9.0
Chunk given slice into a fixed number of parts.
- Chunk: fixed number of parts, variable part size.
- Split: variable number of parts, fixed part size.
NOTE: If the number of parts exceeds the size of the source slice then the resulting slice will contain one element slices for each element in the source slice and nil slices for the remaining entries.
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.
func SelectErr ¶ added in v0.4.1
SelectErr allows the selector to return an error which is then returned to the caller.
func Split ¶ added in v0.2.0
Split given slice into equal sized parts.
- Chunk: fixed number of parts, variable part size.
- Split: variable number of parts, fixed part size.
NOTE: The last part may have an unequal length if the size of the source slice is not divisible by the required length without leaving a remainder.
Types ¶
This section is empty.