Documentation
¶
Overview ¶
The try 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 value-and-error sequences.
Index ¶
- func All[T any](it iter.Seq2[T, error], pred func(v T, err error) (bool, error)) (bool, error)
- func And[T any](preds ...func(v T, err error) (bool, error)) func(T, error) (bool, error)
- func Any[T any](it iter.Seq2[T, error], pred func(v T, err error) (bool, error)) (bool, error)
- func Concat[T any](iters ...iter.Seq2[T, error]) iter.Seq2[T, error]
- func ConcatMany[T any](iters iter.Seq[iter.Seq2[T, error]]) iter.Seq2[T, error]
- func FMap[T, U any](it iter.Seq2[T, error], fn func(v T, err error) (U, bool, error)) iter.Seq2[U, error]
- func Filter[T any](it iter.Seq2[T, error], fn func(v T, err error) (bool, error)) iter.Seq2[T, error]
- func Map[T, U any](it iter.Seq2[T, error], fn func(v T, err error) (U, error)) iter.Seq2[U, error]
- func MapUntil[T, U any](it iter.Seq2[T, error], fn func(it iter.Seq[T]) iter.Seq[U]) iter.Seq2[U, error]
- func Must[T any](it iter.Seq2[T, error]) iter.Seq[T]
- func NoError[T any](_ T, err error) (bool, error)
- func NoErrors[T any](it iter.Seq2[T, error]) iter.Seq[T]
- func Not[T any](pred func(v T, err error) (bool, error)) func(T, error) (bool, error)
- func OK[T any](it iter.Seq[T]) iter.Seq2[T, error]
- func Or[T any](preds ...func(v T, err error) (bool, error)) func(T, error) (bool, error)
- func PackAll[T any](it iter.Seq2[T, error]) iter.Seq[fx.Result[T]]
- func Reduce[T, U any](it iter.Seq2[T, error], init U, fn func(acc U, v T, err error) (U, error)) (_ U, err error)
- func Take[T any](it iter.Seq2[T, error], n int) iter.Seq2[T, error]
- func UnpackAll[T any](it iter.Seq[fx.Result[T]]) iter.Seq2[T, error]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶
And combines a list of predicates into a predicate that returns true if every predicate in the list returns true.
func ConcatMany ¶
ConcatMany returns an iterator that returns values from each iterator in sequence.
func FMap ¶
func FMap[T, U any](it iter.Seq2[T, error], fn func(v T, err error) (U, bool, error)) iter.Seq2[U, error]
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 Filter ¶
func Filter[T any](it iter.Seq2[T, error], fn func(v T, err error) (bool, error)) iter.Seq2[T, error]
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 MapUntil ¶ added in v2.0.4
func MapUntil[T, U any](it iter.Seq2[T, error], fn func(it iter.Seq[T]) iter.Seq[U]) iter.Seq2[U, error]
MapUntil invokes fn with a view of the input sequence as if it had no errors. This view terminates on the first error (if any) in the input. The output is an iter.Seq2[U, error]; if an error is encountered in the input, the output will terminate with that error.
func Must ¶
Must transforms a sequence of (T, error) pairs into a sequence of T values. If any element of the input sequence contains a non-nil error, the returned iterator will panic when that error is observed.
func NoErrors ¶ added in v2.0.2
NoErrors transforms a sequence of (T, error) pairs into a sequence of T values, including only those values from pairs where the error is nil.
Equivalent to Must(Filter(it, NoError[T])).
func Or ¶
Or combines a list of predicates into a predicate that returns true if any predicate in the list returns true.
func PackAll ¶
PackAll transforms a sequence of (T, error) pairs into a sequence of Result[T] values.
func Reduce ¶
func Reduce[T, U any](it iter.Seq2[T, error], init U, fn func(acc U, v T, err error) (U, error)) (_ U, err error)
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.
Types ¶
This section is empty.