Documentation
¶
Overview ¶
The fx package contains a number of common utilities for functional programmers, such as map/reduce/filter. The package also contains utility types for working with pairs, value-or-error enumerations, and sets.
Index ¶
- func All[T any](it iter.Seq[T], pred func(v T) bool) bool
- func All2[T, U any](it iter.Seq2[T, U], pred func(t T, u U) bool) bool
- func And[T any](preds ...func(v T) bool) func(T) bool
- func And2[T, U any](preds ...func(t T, u U) bool) func(T, U) bool
- func Any[T any](it iter.Seq[T], pred func(v T) bool) bool
- func Any2[T, U any](it iter.Seq2[T, U], pred func(t T, u U) bool) bool
- func Concat[T any](iters ...iter.Seq[T]) iter.Seq[T]
- func Concat2[T, U any](iters ...iter.Seq2[T, U]) iter.Seq2[T, U]
- func ConcatMany[T any](iters iter.Seq[iter.Seq[T]]) iter.Seq[T]
- func ConcatMany2[T, U any](iters iter.Seq[iter.Seq2[T, U]]) iter.Seq2[T, U]
- func Contains[T comparable](it iter.Seq[T], t T) bool
- func Empty[T any]() iter.Seq[T]
- func Empty2[T, U any]() iter.Seq2[T, U]
- func Enumerate[T any](len func() int, item func(int) T) iter.Seq2[int, T]
- func FMap[T, U any](it iter.Seq[T], fn func(v T) (U, bool)) iter.Seq[U]
- func FMap2[T, U, V, W any](it iter.Seq2[T, U], fn func(t T, u U) (V, W, bool)) iter.Seq2[V, W]
- func FMap2Pack[T, U, V any](it iter.Seq2[T, U], fn func(t T, u U) (V, bool)) iter.Seq[V]
- func FMapUnpack[T, U, V any](it iter.Seq[T], fn func(v T) (U, V, bool)) iter.Seq2[U, V]
- func Filter[T any](it iter.Seq[T], fn func(v T) bool) iter.Seq[T]
- func Filter2[T, U any](it iter.Seq2[T, U], fn func(t T, u U) bool) iter.Seq2[T, U]
- func First[T any](it iter.Seq[T]) (t T, ok bool)
- func First2[T, U any](it iter.Seq2[T, U]) (t T, u U, ok bool)
- func Last[T any](it iter.Seq[T]) (last T, ok bool)
- func Last2[T, U any](it iter.Seq2[T, U]) (lastT T, lastU U, ok bool)
- func Map[T, U any](it iter.Seq[T], fn func(v T) U) iter.Seq[U]
- func Map2[T, U, V, W any](it iter.Seq2[T, U], fn func(t T, u U) (V, W)) iter.Seq2[V, W]
- func Map2Pack[T, U, V any](it iter.Seq2[T, U], fn func(t T, u U) V) iter.Seq[V]
- func MapUnpack[T, U, V any](it iter.Seq[T], fn func(v T) (U, V)) iter.Seq2[U, V]
- func MaxRange(max int) iter.Seq[int]
- func MinRange(min int) iter.Seq[int]
- func Not[T any](pred func(v T) bool) func(T) bool
- func Not2[T, U any](pred func(t T, u U) bool) func(T, U) bool
- func OfType[U, T any](it iter.Seq[T]) iter.Seq[U]
- func OfType2[U, K, T any](it iter.Seq2[K, T]) iter.Seq2[K, U]
- func Only[T any](v T) iter.Seq[T]
- func Only2[T, U any](t T, u U) iter.Seq2[T, U]
- func Or[T any](preds ...func(v T) bool) func(T) bool
- func Or2[T, U any](preds ...func(t T, u U) bool) func(T, U) bool
- func PackAll[K, V any](it iter.Seq2[K, V]) iter.Seq[Pair[K, V]]
- func Range(min, max int) iter.Seq[int]
- func Reduce[T, U any](it iter.Seq[T], init U, fn func(acc U, v T) U) U
- func Reduce2[T, U, V any](it iter.Seq2[T, U], init V, fn func(acc V, t T, u U) V) V
- func Skip[T any](it iter.Seq[T], n int) iter.Seq[T]
- func Skip2[T, U any](it iter.Seq2[T, U], n int) iter.Seq2[T, U]
- func Some[T any](v T) *T
- func Take[T any](it iter.Seq[T], n int) iter.Seq[T]
- func Take2[T, U any](it iter.Seq2[T, U], n int) iter.Seq2[T, U]
- func TryFunc[T, U any](fn func(t T) (U, error)) func(t T) Result[U]
- func UnpackAll[K, V any](it iter.Seq[Pair[K, V]]) iter.Seq2[K, V]
- func Values[T any](len func() int, item func(int) T) iter.Seq[T]
- type Pair
- type Result
- type Set
- func (s Set[T]) Add(v T)
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Has(v T) bool
- func (s Set[T]) Intersect(other Set[T])
- func (s Set[T]) Len() int
- func (s Set[T]) Remove(v T)
- func (s Set[T]) String() string
- func (s Set[T]) ToSlice() []T
- func (s Set[T]) Union(other Set[T])
- func (s Set[T]) Values() iter.Seq[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All2 ¶ added in v2.0.3
All2 returns true if pred returns true for every element of the input slice.
func And ¶
And combines a list of predicates into a predicate that returns true if every predicate in the list returns true.
func And2 ¶ added in v2.0.3
And2 combines a list of predicates into a predicate that returns true if every predicate in the list returns true.
func Any2 ¶ added in v2.0.3
Any2 returns true if pred returns true for any element of the input slice.
func Concat2 ¶ added in v2.0.3
Concat2 returns an iterator that returns values from each iterator in sequence.
func ConcatMany ¶
ConcatMany returns an iterator that returns values from each iterator in sequence.
func ConcatMany2 ¶ added in v2.0.3
ConcatMany2 returns an iterator that returns values from each iterator in sequence.
func Contains ¶ added in v2.0.10
func Contains[T comparable](it iter.Seq[T], t T) bool
Contains returns true if the input sequence contains t.
func Enumerate ¶ added in v2.0.12
Enumerate returns a sequence of (index, value) pairs from the given length and element accessor.
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 FMap2 ¶ added in v2.0.3
FMap2 returns a sequence of values computed by invoking fn on each element of the input slice and returning only mapped values for with fn returns true.
func FMap2Pack ¶ added in v2.0.10
FMap2Pack returns a sequence of values computed by invoking fn on each element of the input slice 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 Filter2 ¶ added in v2.0.3
Filter2 returns a sequence of values computed by invoking fn on each element of the input slice and returning only those elements for with fn returns true.
func Map2 ¶ added in v2.0.3
Map2 invokes fn on each value in the input slice and returns the results.
func Map2Pack ¶ added in v2.0.10
Map2Pack invokes fn on each value in the input slice and returns the results.
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 OfType2 ¶ added in v2.0.10
OfType2 returns a sequence composed of all elements in the input sequence where the second value is of type U.
func Or ¶
Or combines a list of predicates into a predicate that returns true if any predicate in the list returns true.
func Or2 ¶ added in v2.0.3
Or2 combines a list of predicates into a predicate that returns true if any predicate in the list returns true.
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 Reduce2 ¶ added in v2.0.3
Reduce2 calls fn on each element of the input slice, passing in the current value of the accumulator with each invocation and updating the accumulator to the result of fn after each invocation.
func Take2 ¶ added in v2.0.3
Take2 returns an iterator that takes at most n values from the input slice.
func TryFunc ¶
TryFunc wraps a function that returns (U, error) so that it instead returns a Result[U].
Types ¶
type Pair ¶
type Pair[T, U any] struct { Fst T Snd U }
A Pair is a pair of (possibly-differently) typed values.
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
A Result wraps a (T, error) tuple in a single value.
func AndThen ¶ added in v2.0.5
AndThen invokes fn and returns the result if r is not an error. Otherwise, AndThen returns a new Result that wraps r's error.
type Set ¶
type Set[T comparable] map[T]struct{}
A Set represents a set of comparable values.
func NewSet ¶ added in v2.0.8
func NewSet[T comparable](values ...T) Set[T]
NewSet returns a new set that contains the given elements.
func (Set[T]) String ¶ added in v2.0.6
String returns a pretty-printed representation of the values in the set.
func (Set[T]) ToSlice ¶
func (s Set[T]) ToSlice() []T
ToSlice returns a slice that contains the values in the set. The ordering of elements is undefined.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
The maps package contains a number of common utilities for functional programmers, such as map/reduce/filter.
|
The maps package contains a number of common utilities for functional programmers, such as map/reduce/filter. |
|
The sets package contains a number of common utilities for functional programmers, such as map/reduce/filter.
|
The sets package contains a number of common utilities for functional programmers, such as map/reduce/filter. |
|
The slices package contains a number of common utilities for functional programmers, such as map/reduce/filter.
|
The slices package contains a number of common utilities for functional programmers, such as map/reduce/filter. |
|
The try package contains a number of common utilities for functional programmers, such as map/reduce/filter.
|
The try package contains a number of common utilities for functional programmers, such as map/reduce/filter. |