Documentation
¶
Index ¶
- func Ap[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], ...](fa GEA) func(GEFAB) GEB
- func ApS[GS1 ~func(R) O.Option[S1], GS2 ~func(R) O.Option[S2], GT ~func(R) O.Option[T], ...](setter func(T) func(S1) S2, fa GT) func(GS1) GS2
- func Ask[GEE ~func(E) O.Option[E], E any]() GEE
- func Asks[GA ~func(E) A, GEA ~func(E) O.Option[A], E, A any](r GA) GEA
- func Bind[GS1 ~func(R) O.Option[S1], GS2 ~func(R) O.Option[S2], GT ~func(R) O.Option[T], ...](setter func(T) func(S1) S2, f func(S1) GT) func(GS1) GS2
- func BindTo[GS1 ~func(R) O.Option[S1], GT ~func(R) O.Option[T], R, S1, T any](setter func(T) S1) func(GT) GS1
- func Chain[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], E, A, B any](f func(A) GEB) func(GEA) GEB
- func ChainOptionK[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], E, A, B any](f func(A) O.Option[B]) func(ma GEA) GEB
- func Curry0[GEA ~func(R) O.Option[A], R, A any](f func(R) (A, bool)) GEA
- func Curry1[GEA ~func(R) O.Option[A], R, T1, A any](f func(R, T1) (A, bool)) func(T1) GEA
- func Curry2[GEA ~func(R) O.Option[A], R, T1, T2, A any](f func(R, T1, T2) (A, bool)) func(T1) func(T2) GEA
- func Curry3[GEA ~func(R) O.Option[A], R, T1, T2, T3, A any](f func(R, T1, T2, T3) (A, bool)) func(T1) func(T2) func(T3) GEA
- func Do[GS ~func(R) O.Option[S], R, S any](empty S) GS
- func Flap[GEFAB ~func(E) O.Option[func(A) B], GEB ~func(E) O.Option[B], E, A, B any](a A) func(GEFAB) GEB
- func Flatten[GEA ~func(E) O.Option[A], GGA ~func(E) O.Option[GEA], E, A any](mma GGA) GEA
- func Fold[GEA ~func(E) O.Option[A], GB ~func(E) B, E, A, B any](onNone func() GB, onRight func(A) GB) func(GEA) GB
- func From0[GEA ~func(R) O.Option[A], R, A any](f func(R) (A, bool)) func() GEA
- func From1[GEA ~func(R) O.Option[A], R, T1, A any](f func(R, T1) (A, bool)) func(T1) GEA
- func From2[GEA ~func(R) O.Option[A], R, T1, T2, A any](f func(R, T1, T2) (A, bool)) func(T1, T2) GEA
- func From3[GEA ~func(R) O.Option[A], R, T1, T2, T3, A any](f func(R, T1, T2, T3) (A, bool)) func(T1, T2, T3) GEA
- func FromOption[GEA ~func(E) O.Option[A], E, A any](e O.Option[A]) GEA
- func FromPredicate[GEA ~func(E) O.Option[A], E, A any](pred func(A) bool) func(A) GEA
- func FromReader[GA ~func(E) A, GEA ~func(E) O.Option[A], E, A any](r GA) GEA
- func GetOrElse[GEA ~func(E) O.Option[A], GA ~func(E) A, E, A any](onNone func() GA) func(GEA) GA
- func Let[GS1 ~func(R) O.Option[S1], GS2 ~func(R) O.Option[S2], R, S1, S2, T any](key func(T) func(S1) S2, f func(S1) T) func(GS1) GS2
- func LetTo[GS1 ~func(R) O.Option[S1], GS2 ~func(R) O.Option[S2], R, S1, S2, B any](key func(B) func(S1) S2, b B) func(GS1) GS2
- func Local[GA1 ~func(R1) O.Option[A], GA2 ~func(R2) O.Option[A], R2, R1, E, A any](f func(R2) R1) func(GA1) GA2
- func MakeReaderOption[GEA ~func(E) O.Option[A], E, A any](f func(E) O.Option[A]) GEA
- func Map[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], E, A, B any](f func(A) B) func(GEA) GEB
- func MonadAp[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], ...](fab GEFAB, fa GEA) GEB
- func MonadChain[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], E, A, B any](ma GEA, f func(A) GEB) GEB
- func MonadChainOptionK[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], E, A, B any](ma GEA, f func(A) O.Option[B]) GEB
- func MonadFlap[GEFAB ~func(E) O.Option[func(A) B], GEB ~func(E) O.Option[B], E, A, B any](fab GEFAB, a A) GEB
- func MonadMap[GEA ~func(E) O.Option[A], GEB ~func(E) O.Option[B], E, A, B any](fa GEA, f func(A) B) GEB
- func MonadTraverseArray[GB ~func(E) O.Option[B], GBS ~func(E) O.Option[BBS], AAS ~[]A, BBS ~[]B, ...](ma AAS, f func(A) GB) GBS
- func Of[GEA ~func(E) O.Option[A], E, A any](a A) GEA
- func SequenceArray[GA ~func(E) O.Option[A], GAS ~func(E) O.Option[AAS], AAS ~[]A, GAAS ~[]GA, ...](ma GAAS) GAS
- func SequenceT1[GA ~func(E) O.Option[A], GTA ~func(E) O.Option[T.Tuple1[A]], E, A any](a GA) GTA
- func SequenceT2[GA ~func(E) O.Option[A], GB ~func(E) O.Option[B], ...](a GA, b GB) GTAB
- func SequenceT3[GA ~func(E) O.Option[A], GB ~func(E) O.Option[B], GC ~func(E) O.Option[C], ...](a GA, b GB, c GC) GTABC
- func SequenceT4[GA ~func(E) O.Option[A], GB ~func(E) O.Option[B], GC ~func(E) O.Option[C], ...](a GA, b GB, c GC, d GD) GTABCD
- func Some[GEA ~func(E) O.Option[A], E, A any](r A) GEA
- func SomeReader[GA ~func(E) A, GEA ~func(E) O.Option[A], E, A any](r GA) GEA
- func TraverseArray[GB ~func(E) O.Option[B], GBS ~func(E) O.Option[BBS], AAS ~[]A, BBS ~[]B, ...](f func(A) GB) func(AAS) GBS
- func TraverseArrayWithIndex[GB ~func(E) O.Option[B], GBS ~func(E) O.Option[BBS], AAS ~[]A, BBS ~[]B, ...](f func(int, A) GB) func(AAS) GBS
- func Uncurry1[GEA ~func(R) O.Option[A], R, T1, A any](f func(T1) GEA) func(R, T1) (A, bool)
- func Uncurry2[GEA ~func(R) O.Option[A], R, T1, T2, A any](f func(T1) func(T2) GEA) func(R, T1, T2) (A, bool)
- func Uncurry3[GEA ~func(R) O.Option[A], R, T1, T2, T3, A any](f func(T1) func(T2) func(T3) GEA) func(R, T1, T2, T3) (A, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApS ¶
func ApS[GS1 ~func(R) O.Option[S1], GS2 ~func(R) O.Option[S2], GT ~func(R) O.Option[T], R, S1, S2, T any]( setter func(T) func(S1) S2, fa GT, ) 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.
Example:
type State struct {
Config Config
User User
}
type Env struct {
ConfigService ConfigService
UserService UserService
}
// These operations are independent and can be combined with ApS
getConfig := func(env Env) either.Either[error, Config] {
return env.ConfigService.Load()
}
getUser := func(env Env) either.Either[error, User] {
return env.UserService.GetCurrent()
}
result := F.Pipe2(
generic.Do[ReaderEither[Env, error, State], Env, error, State](State{}),
generic.ApS[...](
func(cfg Config) func(State) State {
return func(s State) State { s.Config = cfg; return s }
},
getConfig,
),
generic.ApS[...](
func(user User) func(State) State {
return func(s State) State { s.User = user; return s }
},
getUser,
),
)
func Bind ¶
func Bind[GS1 ~func(R) O.Option[S1], GS2 ~func(R) O.Option[S2], GT ~func(R) O.Option[T], R, S1, S2, T any]( setter func(T) func(S1) S2, f func(S1) GT, ) 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 and access the shared environment.
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 {
Config Config
User User
}
type Env struct {
ConfigService ConfigService
UserService UserService
}
result := F.Pipe2(
generic.Do[ReaderEither[Env, error, State], Env, error, State](State{}),
generic.Bind[ReaderEither[Env, error, State], ReaderEither[Env, error, State], ReaderEither[Env, error, Config], Env, error, State, State, Config](
func(cfg Config) func(State) State {
return func(s State) State { s.Config = cfg; return s }
},
func(s State) ReaderEither[Env, error, Config] {
return func(env Env) either.Either[error, Config] {
return env.ConfigService.Load()
}
},
),
generic.Bind[ReaderEither[Env, error, State], ReaderEither[Env, error, State], ReaderEither[Env, error, User], Env, error, State, State, User](
func(user User) func(State) State {
return func(s State) State { s.User = user; return s }
},
func(s State) ReaderEither[Env, error, User] {
// This can access s.Config from the previous step
return func(env Env) either.Either[error, User] {
return env.UserService.GetUserForConfig(s.Config)
}
},
),
)
func BindTo ¶
func BindTo[GS1 ~func(R) O.Option[S1], GT ~func(R) O.Option[T], R, S1, T any]( setter func(T) S1, ) func(GT) GS1
BindTo initializes a new state [S1] from a value [T]
func ChainOptionK ¶
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 {
Config Config
User User
}
type Env struct {
ConfigService ConfigService
UserService UserService
}
result := generic.Do[ReaderEither[Env, error, State], Env, error, State](State{})
func FromPredicate ¶
func FromReader ¶
func Let ¶
func Let[GS1 ~func(R) O.Option[S1], GS2 ~func(R) O.Option[S2], R, S1, S2, T any]( key func(T) func(S1) S2, f func(S1) T, ) 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(R) O.Option[S1], GS2 ~func(R) O.Option[S2], R, 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 Local ¶
func Local[GA1 ~func(R1) O.Option[A], GA2 ~func(R2) O.Option[A], R2, R1, E, A any](f func(R2) R1) func(GA1) GA2
Local changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s `contramap`).
func MakeReaderOption ¶
func MonadChain ¶
func MonadChainOptionK ¶
func MonadTraverseArray ¶
func MonadTraverseArray[GB ~func(E) O.Option[B], GBS ~func(E) O.Option[BBS], AAS ~[]A, BBS ~[]B, E, A, B any](ma AAS, f func(A) GB) GBS
MonadTraverseArray transforms an array
func SequenceArray ¶
func SequenceArray[GA ~func(E) O.Option[A], GAS ~func(E) O.Option[AAS], AAS ~[]A, GAAS ~[]GA, E, A any](ma GAAS) GAS
SequenceArray converts a homogeneous sequence of either into an either of sequence
func SequenceT1 ¶
func SequenceT2 ¶
func SequenceT3 ¶
func SequenceT4 ¶
func SomeReader ¶
func TraverseArray ¶
func TraverseArray[GB ~func(E) O.Option[B], GBS ~func(E) O.Option[BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS
TraverseArray transforms an array
func TraverseArrayWithIndex ¶
func TraverseArrayWithIndex[GB ~func(E) O.Option[B], GBS ~func(E) O.Option[BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS
TraverseArrayWithIndex transforms an array
Types ¶
This section is empty.