Documentation
¶
Overview ¶
Package slices provides generic higher-order functions over slices of values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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.