Documentation
¶
Overview ¶
Package slices provides generic higher-order functions over slices of values.
Index ¶
- func Copy[X interface{ ... }](xs []X) []X
- func Filter[X any](f func(X) bool, xs []X) []X
- func FlatMap[X any, Y any](f func(X) []Y, xs []X) []Y
- func ForEach[X any](f func(X), xs []X)
- func FromArgs[X any](xs ...X) []X
- func Map[X any, Y any](f func(X) Y, xs []X) []Y
- func Reduce[X any](initial X, f func(X, X) X, xs []X) X
- func Reducer[X any](initial X, f func(X, X) X) func(xs []X) X
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶ added in v2.11.0
func Copy[X interface{ Copy() X }](xs []X) []X
Copy deeply copies a slice of elements that each, in turn, must be copied using their own Copy method.
func Filter ¶ added in v2.7.0
Filter applies function "f : X => bool" to each value X of the input slice, and returns a new slice containing only each X for which f(X) is true.
If f(X) is false for every item, this function may return a nil slice.
func FlatMap ¶
FlatMap applies function "f : X => []Y" to each value of the input slice, and returns a new slice of each output in sequence. The output sequence is "flattened" so that each slice returned by f is concatenated into a single slice.
If the input slice is a nil slice, the return value is also a nil slice. If f returns a nil slice, it is not included in the output.
For a lazy version, see the iter package.
func ForEach ¶ added in v2.10.0
func ForEach[X any](f func(X), xs []X)
ForEach applies the void function "f(x)" to each value X of the input slice.
func FromArgs ¶ added in v2.10.0
func FromArgs[X any](xs ...X) []X
FromArgs returns the slice of the variadic arguments list.
func Map ¶
Map applies function "f : X => Y" to each value of the input slice, and returns a new slice of each output in sequence.
If the input slice is a nil slice, the return value is also a nil slice.
For a lazy version, see the iter package.
func Reduce ¶ added in v2.7.0
func Reduce[X any](initial X, f func(X, X) X, xs []X) X
Reduce applies function f to each element of the slice (in increasing order of element index) with the previous return value from f as the first argument and the element as the second argument (for the first call to f, the supplied initial value is used instead of a return value), returning the final value returned by f.
If the input slice is empty, the result is the initial value.
Types ¶
This section is empty.