Documentation
¶
Index ¶
- func Ap[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], ...](fa GEA) func(GEFAB) GEB
- func ApEitherS[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], ...](setter func(T) func(S1) S2, fa ET.Either[E, T]) func(GS1) GS2
- func ApReaderS[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], GT ~func(R) T, ...](setter func(T) func(S1) S2, fa GT) func(GS1) GS2
- func ApS[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], ...](setter func(T) func(S1) S2, fa GT) func(GS1) GS2
- func Ask[GEE ~func(E) ET.Either[L, E], E, L any]() GEE
- func Asks[GA ~func(E) A, GEA ~func(E) ET.Either[L, A], E, L, A any](r GA) GEA
- func BiMap[GA ~func(E) ET.Either[E1, A], GB ~func(E) ET.Either[E2, B], ...](f func(E1) E2, g func(A) B) func(GA) GB
- func Bind[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], ...](setter func(T) func(S1) S2, f func(S1) GT) func(GS1) GS2
- func BindEitherK[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], ...](setter func(T) func(S1) S2, f func(S1) ET.Either[E, T]) func(GS1) GS2
- func BindReaderK[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], GRT ~func(R) T, ...](setter func(T) func(S1) S2, f func(S1) GRT) func(GS1) GS2
- func BindTo[GS1 ~func(R) ET.Either[E, S1], GT ~func(R) ET.Either[E, T], R, E, S1, T any](setter func(T) S1) func(GT) GS1
- func BindToEither[GS1 ~func(R) ET.Either[E, S1], R, E, S1, T any](setter func(T) S1) func(ET.Either[E, T]) GS1
- func BindToReader[GS1 ~func(R) ET.Either[E, S1], GT ~func(R) T, R, E, S1, T any](setter func(T) S1) func(GT) GS1
- func Chain[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], L, E, A, B any](f func(A) GEB) func(GEA) GEB
- func ChainEitherK[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], L, E, A, B any](f func(A) ET.Either[L, B]) func(ma GEA) GEB
- func ChainOptionK[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], L, E, A, B any](onNone func() L) func(func(A) O.Option[B]) func(GEA) GEB
- func ChainReaderK[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], GB ~func(E) B, ...](f func(A) GB) func(GEA) GEB
- func Curry0[GEA ~func(R) ET.Either[error, A], R, A any](f func(R) (A, error)) GEA
- func Curry1[GEA ~func(R) ET.Either[error, A], R, T1, A any](f func(R, T1) (A, error)) func(T1) GEA
- func Curry2[GEA ~func(R) ET.Either[error, A], R, T1, T2, A any](f func(R, T1, T2) (A, error)) func(T1) func(T2) GEA
- func Curry3[GEA ~func(R) ET.Either[error, A], R, T1, T2, T3, A any](f func(R, T1, T2, T3) (A, error)) func(T1) func(T2) func(T3) GEA
- func Do[GS ~func(R) ET.Either[E, S], R, E, S any](empty S) GS
- func Flap[GEFAB ~func(E) ET.Either[L, func(A) B], GEB ~func(E) ET.Either[L, B], ...](a A) func(GEFAB) GEB
- func Flatten[GEA ~func(E) ET.Either[L, A], GGA ~func(E) ET.Either[L, GEA], L, E, A any](mma GGA) GEA
- func Fold[GEA ~func(E) ET.Either[L, A], GB ~func(E) B, E, L, A, B any](onLeft func(L) GB, onRight func(A) GB) func(GEA) GB
- func From0[GEA ~func(R) ET.Either[error, A], R, A any](f func(R) (A, error)) func() GEA
- func From1[GEA ~func(R) ET.Either[error, A], R, T1, A any](f func(R, T1) (A, error)) func(T1) GEA
- func From2[GEA ~func(R) ET.Either[error, A], R, T1, T2, A any](f func(R, T1, T2) (A, error)) func(T1, T2) GEA
- func From3[GEA ~func(R) ET.Either[error, A], R, T1, T2, T3, A any](f func(R, T1, T2, T3) (A, error)) func(T1, T2, T3) GEA
- func FromEither[GEA ~func(E) ET.Either[L, A], L, E, A any](e ET.Either[L, A]) GEA
- func FromPredicate[GEA ~func(E) ET.Either[L, A], L, E, A any](pred func(A) bool, onFalse func(A) L) func(A) GEA
- func FromReader[GA ~func(E) A, GEA ~func(E) ET.Either[L, A], L, E, A any](r GA) GEA
- func GetOrElse[GEA ~func(E) ET.Either[L, A], GA ~func(E) A, E, L, A any](onLeft func(L) GA) func(GEA) GA
- func Left[GEA ~func(E) ET.Either[L, A], L, E, A any](l L) GEA
- func LeftReader[GL ~func(E) L, GEA ~func(E) ET.Either[L, A], L, E, A any](l GL) GEA
- func Let[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], ...](key func(T) func(S1) S2, f func(S1) T) func(GS1) GS2
- func LetTo[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], ...](key func(B) func(S1) S2, b B) func(GS1) GS2
- func Local[GA1 ~func(R1) ET.Either[E, A], GA2 ~func(R2) ET.Either[E, A], R2, R1, E, A any](f func(R2) R1) func(GA1) GA2
- func MakeReaderEither[GEA ~func(E) ET.Either[L, A], L, E, A any](f func(E) ET.Either[L, A]) GEA
- func Map[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], L, E, A, B any](f func(A) B) func(GEA) GEB
- func MapLeft[GA1 ~func(C) ET.Either[E1, A], GA2 ~func(C) ET.Either[E2, A], C, E1, E2, A any](f func(E1) E2) func(GA1) GA2
- func MonadAp[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], ...](fab GEFAB, fa GEA) GEB
- func MonadBiMap[GA ~func(E) ET.Either[E1, A], GB ~func(E) ET.Either[E2, B], ...](fa GA, f func(E1) E2, g func(A) B) GB
- func MonadChain[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], L, E, A, B any](ma GEA, f func(A) GEB) GEB
- func MonadChainEitherK[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], L, E, A, B any](ma GEA, f func(A) ET.Either[L, B]) GEB
- func MonadChainReaderK[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], GB ~func(E) B, ...](ma GEA, f func(A) GB) GEB
- func MonadFlap[GEFAB ~func(E) ET.Either[L, func(A) B], GEB ~func(E) ET.Either[L, B], ...](fab GEFAB, a A) GEB
- func MonadMap[GEA ~func(E) ET.Either[L, A], GEB ~func(E) ET.Either[L, B], L, E, A, B any](fa GEA, f func(A) B) GEB
- func MonadMapLeft[GA1 ~func(C) ET.Either[E1, A], GA2 ~func(C) ET.Either[E2, A], C, E1, E2, A any](fa GA1, f func(E1) E2) GA2
- func MonadTraverseArray[GB ~func(E) ET.Either[L, B], GBS ~func(E) ET.Either[L, BBS], AAS ~[]A, ...](ma AAS, f func(A) GB) GBS
- func Of[GEA ~func(E) ET.Either[L, A], L, E, A any](a A) GEA
- func OrElse[GEA1 ~func(E) ET.Either[L1, A], GEA2 ~func(E) ET.Either[L2, A], ...](onLeft func(L1) GEA2) func(GEA1) GEA2
- func OrLeft[GEA1 ~func(E) ET.Either[L1, A], GEA2 ~func(E) ET.Either[L2, A], ...](onLeft func(L1) GE2) func(GEA1) GEA2
- func Right[GEA ~func(E) ET.Either[L, A], L, E, A any](r A) GEA
- func RightReader[GA ~func(E) A, GEA ~func(E) ET.Either[L, A], L, E, A any](r GA) GEA
- func SequenceArray[GA ~func(E) ET.Either[L, A], GAS ~func(E) ET.Either[L, AAS], AAS ~[]A, ...](ma GAAS) GAS
- func SequenceT1[GA ~func(E) ET.Either[L, A], GTA ~func(E) ET.Either[L, T.Tuple1[A]], ...](a GA) GTA
- func SequenceT2[GA ~func(E) ET.Either[L, A], GB ~func(E) ET.Either[L, B], ...](a GA, b GB) GTAB
- func SequenceT3[GA ~func(E) ET.Either[L, A], GB ~func(E) ET.Either[L, B], ...](a GA, b GB, c GC) GTABC
- func SequenceT4[GA ~func(E) ET.Either[L, A], GB ~func(E) ET.Either[L, B], ...](a GA, b GB, c GC, d GD) GTABCD
- func TraverseArray[GB ~func(E) ET.Either[L, B], GBS ~func(E) ET.Either[L, BBS], AAS ~[]A, ...](f func(A) GB) func(AAS) GBS
- func TraverseArrayWithIndex[GB ~func(E) ET.Either[L, B], GBS ~func(E) ET.Either[L, BBS], AAS ~[]A, ...](f func(int, A) GB) func(AAS) GBS
- func Uncurry1[GEA ~func(R) ET.Either[error, A], R, T1, A any](f func(T1) GEA) func(R, T1) (A, error)
- func Uncurry2[GEA ~func(R) ET.Either[error, A], R, T1, T2, A any](f func(T1) func(T2) GEA) func(R, T1, T2) (A, error)
- func Uncurry3[GEA ~func(R) ET.Either[error, A], R, T1, T2, T3, A any](f func(T1) func(T2) func(T3) GEA) func(R, T1, T2, T3) (A, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApS ¶
func ApS[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], GT ~func(R) ET.Either[E, T], R, E, 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 BiMap ¶
func BiMap[GA ~func(E) ET.Either[E1, A], GB ~func(E) ET.Either[E2, B], E, E1, E2, A, B any](f func(E1) E2, g func(A) B) func(GA) GB
BiMap maps a pair of functions over the two type arguments of the bifunctor.
func Bind ¶
func Bind[ GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], GT ~func(R) ET.Either[E, T], R, E, 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 BindEitherK ¶
func BindReaderK ¶
func BindTo ¶
func BindTo[GS1 ~func(R) ET.Either[E, S1], GT ~func(R) ET.Either[E, T], R, E, S1, T any]( setter func(T) S1, ) func(GT) GS1
BindTo initializes a new state [S1] from a value [T]
func BindToEither ¶
func BindToReader ¶
func ChainEitherK ¶
func ChainOptionK ¶
func ChainReaderK ¶
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 LeftReader ¶
func Let ¶
func Let[GS1 ~func(R) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], R, E, 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) ET.Either[E, S1], GS2 ~func(R) ET.Either[E, S2], R, E, 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) ET.Either[E, A], GA2 ~func(R2) ET.Either[E, 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 MakeReaderEither ¶
func MapLeft ¶
func MapLeft[GA1 ~func(C) ET.Either[E1, A], GA2 ~func(C) ET.Either[E2, A], C, E1, E2, A any](f func(E1) E2) func(GA1) GA2
MapLeft applies a mapping function to the error channel
func MonadBiMap ¶
func MonadChain ¶
func MonadChainEitherK ¶
func MonadChainReaderK ¶
func MonadMapLeft ¶
func MonadTraverseArray ¶
func MonadTraverseArray[GB ~func(E) ET.Either[L, B], GBS ~func(E) ET.Either[L, BBS], AAS ~[]A, BBS ~[]B, L, E, A, B any](ma AAS, f func(A) GB) GBS
MonadTraverseArray transforms an array
func RightReader ¶
func SequenceArray ¶
func SequenceArray[GA ~func(E) ET.Either[L, A], GAS ~func(E) ET.Either[L, AAS], AAS ~[]A, GAAS ~[]GA, L, 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 TraverseArray ¶
func TraverseArray[GB ~func(E) ET.Either[L, B], GBS ~func(E) ET.Either[L, BBS], AAS ~[]A, BBS ~[]B, L, E, A, B any](f func(A) GB) func(AAS) GBS
TraverseArray transforms an array
func TraverseArrayWithIndex ¶
func TraverseArrayWithIndex[GB ~func(E) ET.Either[L, B], GBS ~func(E) ET.Either[L, BBS], AAS ~[]A, BBS ~[]B, L, E, A, B any](f func(int, A) GB) func(AAS) GBS
TraverseArrayWithIndex transforms an array
Types ¶
This section is empty.