Documentation
¶
Index ¶
- func Bind[S1, S2, B, HKTS1, HKTS2, HKTB any](mchain func(func(S1) HKTS2) func(HKTS1) HKTS2, ...) func(HKTS1) HKTS2
- func BindTo[S1, B, HKTS1, HKTB any](mmap func(func(B) S1) func(HKTB) HKTS1, key func(B) S1) func(fa HKTB) HKTS1
- func MonadBind[S1, S2, B, HKTS1, HKTS2, HKTB any](mchain func(HKTS1, func(S1) HKTS2) HKTS2, mmap func(HKTB, func(B) S2) HKTS2, ...) HKTS2
- func MonadBindTo[S1, B, HKTS1, HKTB any](mmap func(HKTB, func(B) S1) HKTS1, first HKTB, key func(B) S1) HKTS1
- func MonadChain[A, B, HKTA, HKTB any](mchain func(HKTA, Kleisli[A, HKTB]) HKTB, first HKTA, f Kleisli[A, HKTB]) HKTB
- func MonadChainFirst[A, B, HKTA, HKTB any](mchain func(HKTA, Kleisli[A, HKTA]) HKTA, mmap func(HKTB, func(B) A) HKTA, ...) HKTA
- func ToApply[A, B, HKTA, HKTB, HKTFAB any](ap Chainable[A, B, HKTA, HKTB, HKTFAB]) apply.Apply[A, B, HKTA, HKTB, HKTFAB]
- func ToFunctor[A, B, HKTA, HKTB, HKTFAB any](ap Chainable[A, B, HKTA, HKTB, HKTFAB]) functor.Functor[A, B, HKTA, HKTB]
- type Chainable
- type Kleisli
- type Operator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bind ¶
func Bind[S1, S2, B, HKTS1, HKTS2, HKTB any]( mchain func(func(S1) HKTS2) func(HKTS1) HKTS2, mmap func(func(B) S2) func(HKTB) HKTS2, key func(B) func(S1) S2, f func(S1) HKTB, ) func(HKTS1) HKTS2
func BindTo ¶
func BindTo[S1, B, HKTS1, HKTB any]( mmap func(func(B) S1) func(HKTB) HKTS1, key func(B) S1, ) func(fa HKTB) HKTS1
func MonadBind ¶
func MonadBind[S1, S2, B, HKTS1, HKTS2, HKTB any]( mchain func(HKTS1, func(S1) HKTS2) HKTS2, mmap func(HKTB, func(B) S2) HKTS2, first HKTS1, key func(B) func(S1) S2, f func(S1) HKTB, ) HKTS2
func MonadBindTo ¶
func MonadBindTo[S1, B, HKTS1, HKTB any]( mmap func(HKTB, func(B) S1) HKTS1, first HKTB, key func(B) S1, ) HKTS1
func MonadChain ¶
func MonadChainFirst ¶
func MonadChainFirst[A, B, HKTA, HKTB any]( mchain func(HKTA, Kleisli[A, HKTA]) HKTA, mmap func(HKTB, func(B) A) HKTA, first HKTA, f Kleisli[A, HKTB], ) HKTA
HKTA=HKT[A] HKTB=HKT[B]
Types ¶
type Chainable ¶
type Chainable[A, B, HKTA, HKTB, HKTFAB any] interface { apply.Apply[A, B, HKTA, HKTB, HKTFAB] // Chain sequences computations where the second computation depends on the // value produced by the first. // // Takes a function that produces a new context-wrapped value based on the // unwrapped input, and returns a function that applies this to a context-wrapped // input, flattening the nested context. Chain(func(A) HKTB) func(HKTA) HKTB }
Chainable represents a type that supports sequential composition of computations, where each computation depends on the result of the previous one.
Chainable extends Apply by adding the Chain method (also known as flatMap or bind), which allows for dependent sequencing of computations. Unlike Ap, which combines independent computations, Chain allows the structure of the second computation to depend on the value produced by the first.
A Chainable must satisfy the following laws:
Associativity:
Chain(f)(Chain(g)(m)) == Chain(x => Chain(f)(g(x)))(m)
Type Parameters:
- A: The input value type
- B: The output value type after chaining
- HKTA: The higher-kinded type containing A
- HKTB: The higher-kinded type containing B
- HKTFAB: The higher-kinded type containing a function from A to B
Example:
// Given a Chainable for Option
var c Chainable[int, string, Option[int], Option[string], Option[func(int) string]]
chainFn := c.Chain(func(x int) Option[string] {
if x > 0 {
return Some(strconv.Itoa(x))
}
return None[string]()
})
result := chainFn(Some(42)) // Returns Some("42")
Click to show internal directories.
Click to hide internal directories.