Documentation
¶
Overview ¶
The slices package contains a number of common utilities for functional programmers, such as map/reduce/filter. The functions in this package adapt applicable functions in github.com/pgavlin/fx/v2 for more convenient use with slices. Prefer the functions in this package over the use of github.com/pgavlin/fx/v2 with slices.
Index ¶
- func All[S ~[]T, T any](s S, pred func(v T) bool) bool
- func Any[S ~[]T, T any](s S, pred func(v T) bool) bool
- func Contains[S ~[]T, T comparable](s S, t T) bool
- func FMap[S ~[]T, T any, U any](s S, fn func(v T) (U, bool)) iter.Seq[U]
- func FMapUnpack[S ~[]T, T any, U any, V any](s S, fn func(v T) (U, V, bool)) iter.Seq2[U, V]
- func Filter[S ~[]T, T any](s S, fn func(v T) bool) iter.Seq[T]
- func First[S ~[]T, T any](s S) (T, bool)
- func Last[S ~[]T, T any](s S) (T, bool)
- func Map[S ~[]T, T any, U any](s S, fn func(v T) U) iter.Seq[U]
- func MapUnpack[S ~[]T, T any, U any, V any](s S, fn func(v T) (U, V)) iter.Seq2[U, V]
- func OfType[U any, S ~[]T, T any](s S) iter.Seq[U]
- func Reduce[S ~[]T, T any, U any](s S, init U, fn func(acc U, v T) U) U
- func Skip[S ~[]T, T any](s S, n int) iter.Seq[T]
- func Take[S ~[]T, T any](s S, n int) iter.Seq[T]
- func TryCollect[T any](it iter.Seq2[T, error]) ([]T, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶ added in v2.0.10
func Contains[S ~[]T, T comparable](s S, t T) bool
Contains returns true if the input sequence contains t.
func FMap ¶
FMap returns a sequence of values computed by invoking fn on each element of the input sequence and returning only mapped values for with fn returns true.
func FMapUnpack ¶ added in v2.0.10
FMapUnpack returns a sequence of values computed by invoking fn on each element of the input sequence and returning only mapped values for with fn returns true.
func Filter ¶
Filter returns a sequence of values computed by invoking fn on each element of the input sequence and returning only those elements for with fn returns true.
func MapUnpack ¶ added in v2.0.10
MapUnpack invokes fn on each value in the input sequence and returns the results.
func OfType ¶
OfType returns a sequence composed of all elements in the input sequence that are of type U.
func Reduce ¶
Reduce calls fn on each element of the input sequence, passing in the current value of the accumulator with each invocation and updating the accumulator to the result of fn after each invocation.
func TryCollect ¶
TryCollect attempts to collect the values in the input sequence into a slice. If any pair in the input contains a non-nil error, TryCollect halts and returns the values collected up to that point (excluding the value returned with the error) and the error.
Types ¶
This section is empty.