Documentation
¶
Index ¶
- func Any[GU ~func() Option[Pair[GU, U]], FCT ~Predicate[U], U any](pred FCT) func(ma GU) bool
- func Ap[GUV ~func() Option[Pair[GUV, func(U) V]], GV ~func() Option[Pair[GV, V]], ...](ma GU) func(fab GUV) GV
- func ApS[GAS2 ~func() Option[Pair[GAS2, func(A) S2]], GS1 ~func() Option[Pair[GS1, S1]], ...](setter func(A) func(S1) S2, fa GA) func(GS1) GS2
- func Bind[GS1 ~func() Option[Pair[GS1, S1]], GS2 ~func() Option[Pair[GS2, S2]], ...](setter func(A) func(S1) S2, f func(S1) GA) func(GS1) GS2
- func BindTo[GS1 ~func() Option[Pair[GS1, S1]], GA ~func() Option[Pair[GA, A]], S1, A any](setter func(A) S1) func(GA) GS1
- func Chain[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], U, V any](f func(U) GV) func(GU) GV
- func ChainFirst[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], U, V any](f func(U) GV) func(GU) GU
- func Compress[GU ~func() Option[Pair[GU, U]], GB ~func() Option[Pair[GB, bool]], ...](sel GB) func(GU) GU
- func Count[GU ~func() Option[Pair[GU, int]]](start int) GU
- func Current[GU ~func() Option[Pair[GU, U]], U any](m Pair[GU, U]) U
- func Cycle[GU ~func() Option[Pair[GU, U]], U any](ma GU) GU
- func Do[GS ~func() Option[Pair[GS, S]], S any](empty S) GS
- func DropWhile[GU ~func() Option[Pair[GU, U]], U any](pred Predicate[U]) func(GU) GU
- func Empty[GU ~func() Option[Pair[GU, U]], U any]() GU
- func Filter[GU ~func() Option[Pair[GU, U]], FCT ~Predicate[U], U any](f FCT) func(ma GU) GU
- func FilterChain[GVV ~func() Option[Pair[GVV, GV]], GV ~func() Option[Pair[GV, V]], ...](f FCT) func(ma GU) GV
- func FilterMap[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], ...](f FCT) func(ma GU) GV
- func Flatten[GV ~func() Option[Pair[GV, GU]], GU ~func() Option[Pair[GU, U]], U any](ma GV) GU
- func Fold[GU ~func() Option[Pair[GU, U]], U any](m M.Monoid[U]) func(ma GU) U
- func FoldMap[GU ~func() Option[Pair[GU, U]], FCT ~func(U) V, U, V any](m M.Monoid[V]) func(FCT) func(ma GU) V
- func From[GU ~func() Option[Pair[GU, U]], U any](data ...U) GU
- func FromArray[GU ~func() Option[Pair[GU, U]], US ~[]U, U any](as US) GU
- func FromLazy[GU ~func() Option[Pair[GU, U]], LZ ~func() U, U any](l LZ) GU
- func FromReflect[GR ~func() Option[Pair[GR, R.Value]]](val R.Value) GR
- func Let[GS1 ~func() Option[Pair[GS1, S1]], GS2 ~func() Option[Pair[GS2, S2]], ...](key func(A) func(S1) S2, f func(S1) A) func(GS1) GS2
- func LetTo[GS1 ~func() Option[Pair[GS1, S1]], GS2 ~func() Option[Pair[GS2, S2]], ...](key func(B) func(S1) S2, b B) func(GS1) GS2
- func MakeBy[GU ~func() Option[Pair[GU, U]], FCT ~func(int) U, U any](f FCT) GU
- func Map[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], FCT ~func(U) V, ...](f FCT) func(ma GU) GV
- func Monad[A, B any, GA ~func() Option[Pair[GA, A]], GB ~func() Option[Pair[GB, B]], ...]() monad.Monad[A, B, GA, GB, GAB]
- func MonadAp[GUV ~func() Option[Pair[GUV, func(U) V]], GV ~func() Option[Pair[GV, V]], ...](fab GUV, ma GU) GV
- func MonadChain[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], U, V any](ma GU, f func(U) GV) GV
- func MonadChainFirst[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], U, V any](ma GU, f func(U) GV) GU
- func MonadMap[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], U, V any](ma GU, f func(U) V) GV
- func Monoid[GU ~func() Option[Pair[GU, U]], U any]() M.Monoid[GU]
- func Next[GU ~func() Option[Pair[GU, U]], U any](m Pair[GU, U]) GU
- func Of[GU ~func() Option[Pair[GU, U]], U any](a U) GU
- func Reduce[GU ~func() Option[Pair[GU, U]], U, V any](f func(V, U) V, initial V) func(GU) V
- func Repeat[GU ~func() Option[Pair[GU, U]], U any](n int, a U) GU
- func Replicate[GU ~func() Option[Pair[GU, U]], U any](a U) GU
- func Scan[GV ~func() Option[Pair[GV, V]], GU ~func() Option[Pair[GU, U]], ...](f FCT, initial V) func(ma GU) GV
- func StrictUniq[AS ~func() Option[Pair[AS, A]], A comparable](as AS) AS
- func Take[GU ~func() Option[Pair[GU, U]], U any](n int) func(ma GU) GU
- func ToArray[GU ~func() Option[Pair[GU, U]], US ~[]U, U any](u GU) US
- func Uniq[AS ~func() Option[Pair[AS, A]], K comparable, A any](f func(A) K) func(as AS) AS
- func Zip[AS ~func() Option[Pair[AS, A]], BS ~func() Option[Pair[BS, B]], ...](fb BS) func(AS) CS
- func ZipWith[AS ~func() Option[Pair[AS, A]], BS ~func() Option[Pair[BS, B]], ...](fa AS, fb BS, f FCT) CS
- type Lazy
- type Option
- type Pair
- type Predicate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
Any returns `true` if any element of the iterable is `true`. If the iterable is empty, return `false`
func ApS ¶
func ApS[GAS2 ~func() Option[Pair[GAS2, func(A) S2]], GS1 ~func() Option[Pair[GS1, S1]], GS2 ~func() Option[Pair[GS2, S2]], GA ~func() Option[Pair[GA, A]], S1, S2, A any]( setter func(A) func(S1) S2, fa GA, ) func(GS1) GS2
ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently (using Applicative rather than Monad). This allows independent computations to be combined without one depending on the result of the other.
Unlike Bind, which sequences operations, ApS can be used when operations are independent and can conceptually run in parallel. For iterators, this produces the cartesian product.
Example:
type State struct {
X int
Y string
}
// These operations are independent and can be combined with ApS
xIter := generic.Of[Iterator[int]](1, 2, 3)
yIter := generic.Of[Iterator[string]]("a", "b")
result := F.Pipe2(
generic.Do[Iterator[State]](State{}),
generic.ApS[Iterator[func(int) State], Iterator[State], Iterator[State], Iterator[int], State, State, int](
func(x int) func(State) State {
return func(s State) State { s.X = x; return s }
},
xIter,
),
generic.ApS[Iterator[func(string) State], Iterator[State], Iterator[State], Iterator[string], State, State, string](
func(y string) func(State) State {
return func(s State) State { s.Y = y; return s }
},
yIter,
),
) // Produces: {1,"a"}, {1,"b"}, {2,"a"}, {2,"b"}, {3,"a"}, {3,"b"}
func Bind ¶
func Bind[GS1 ~func() Option[Pair[GS1, S1]], GS2 ~func() Option[Pair[GS2, S2]], GA ~func() Option[Pair[GA, A]], S1, S2, A any]( setter func(A) func(S1) S2, f func(S1) GA, ) func(GS1) GS2
Bind attaches the result of a computation to a context [S1] to produce a context [S2]. This enables sequential composition where each step can depend on the results of previous steps. For iterators, this produces the cartesian product where later steps can use values from earlier steps.
The setter function takes the result of the computation and returns a function that updates the context from S1 to S2.
Example:
type State struct {
X int
Y int
}
result := F.Pipe2(
generic.Do[Iterator[State]](State{}),
generic.Bind[Iterator[State], Iterator[State], Iterator[int], State, State, int](
func(x int) func(State) State {
return func(s State) State { s.X = x; return s }
},
func(s State) Iterator[int] {
return generic.Of[Iterator[int]](1, 2, 3)
},
),
generic.Bind[Iterator[State], Iterator[State], Iterator[int], State, State, int](
func(y int) func(State) State {
return func(s State) State { s.Y = y; return s }
},
func(s State) Iterator[int] {
// This can access s.X from the previous step
return generic.Of[Iterator[int]](s.X * 10, s.X * 20)
},
),
) // Produces: {1,10}, {1,20}, {2,20}, {2,40}, {3,30}, {3,60}
func BindTo ¶
func BindTo[GS1 ~func() Option[Pair[GS1, S1]], GA ~func() Option[Pair[GA, A]], S1, A any]( setter func(A) S1, ) func(GA) GS1
BindTo initializes a new state [S1] from a value [T]
func ChainFirst ¶
func Compress ¶
func Compress[GU ~func() Option[Pair[GU, U]], GB ~func() Option[Pair[GB, bool]], CS ~func() Option[Pair[CS, Pair[U, bool]]], U any](sel GB) func(GU) GU
Compress returns an [Iterator] that filters elements from a data [Iterator] returning only those that have a corresponding element in selector [Iterator] that evaluates to `true`. Stops when either the data or selectors iterator has been exhausted.
func Count ¶
Count creates an [Iterator] containing a consecutive sequence of integers starting with the provided start value
func Do ¶
Do creates an empty context of type [S] to be used with the Bind operation. This is the starting point for do-notation style composition.
Example:
type State struct {
X int
Y int
}
result := generic.Do[Iterator[State]](State{})
func DropWhile ¶
DropWhile creates an [Iterator] that drops elements from the [Iterator] as long as the predicate is true; afterwards, returns every element. Note, the [Iterator] does not produce any output until the predicate first becomes false
func FilterChain ¶
func Let ¶
func Let[GS1 ~func() Option[Pair[GS1, S1]], GS2 ~func() Option[Pair[GS2, S2]], S1, S2, A any]( key func(A) func(S1) S2, f func(S1) A, ) func(GS1) GS2
Let attaches the result of a computation to a context [S1] to produce a context [S2]
func LetTo ¶
func LetTo[GS1 ~func() Option[Pair[GS1, S1]], GS2 ~func() Option[Pair[GS2, S2]], S1, S2, B any]( key func(B) func(S1) S2, b B, ) func(GS1) GS2
LetTo attaches the a value to a context [S1] to produce a context [S2]
func MakeBy ¶
MakeBy returns an [Iterator] with an infinite number of elements initialized with `f(i)`
func Monad ¶
func Monad[A, B any, GA ~func() Option[Pair[GA, A]], GB ~func() Option[Pair[GB, B]], GAB ~func() Option[Pair[GAB, func(A) B]]]() monad.Monad[A, B, GA, GB, GAB]
Monad implements the monadic operations for iterators
func MonadChain ¶
func MonadChainFirst ¶
func Repeat ¶
Repeat creates an [Iterator] containing a value repeated the specified number of times. Alias of Replicate combined with Take
func StrictUniq ¶
func StrictUniq[AS ~func() Option[Pair[AS, A]], A comparable](as AS) AS
func Uniq ¶
func Uniq[AS ~func() Option[Pair[AS, A]], K comparable, A any](f func(A) K) func(as AS) AS
func Zip ¶
func Zip[AS ~func() Option[Pair[AS, A]], BS ~func() Option[Pair[BS, B]], CS ~func() Option[Pair[CS, Pair[A, B]]], A, B any](fb BS) func(AS) CS
Zip takes two iterators and returns an iterators of corresponding pairs. If one input iterators is short, excess elements of the longer iterator are discarded
func ZipWith ¶
func ZipWith[AS ~func() Option[Pair[AS, A]], BS ~func() Option[Pair[BS, B]], CS ~func() Option[Pair[CS, C]], FCT ~func(A, B) C, A, B, C any](fa AS, fb BS, f FCT) CS
ZipWith applies a function to pairs of elements at the same index in two iterators, collecting the results in a new iterator. If one input iterator is short, excess elements of the longer iterator are discarded.