midas/continuation
Work with effects as values using continuations.
Types
t is the final return type of the whole computation.
a is the type of the value currently inside the monad.
pub type Continuation(t, a) =
fn(fn(a) -> t) -> t
Values
pub fn each(
over list: List(a),
with f: fn(a) -> fn(fn(b) -> t) -> t,
) -> fn(fn(List(b)) -> t) -> t
Apply a function to each value in a list in order
pub fn fold(
over list: List(a),
from initial: acc,
with f: fn(acc, a) -> fn(fn(acc) -> t) -> t,
) -> fn(fn(acc) -> t) -> t
Iterate over a list of items, and apply each to the given function f.
pub fn return(value: a) -> fn(fn(a) -> t) -> t
Create a continuation that returns the given value when called.
Often called pure.
pub fn then(
cont: fn(fn(a) -> t) -> t,
next: fn(a) -> fn(fn(b) -> t) -> t,
) -> fn(fn(b) -> t) -> t
compose two a continuation with a new function that returns another continuation
This is monad bind.
pub fn try(
result: Result(a, b),
then: fn(a) -> fn(fn(Result(c, b)) -> t) -> t,
) -> fn(fn(Result(c, b)) -> t) -> t
Work with results that are not continuations.
pub fn try_each(
over list: List(a),
with f: fn(a) -> fn(fn(Result(b, c)) -> t) -> t,
) -> fn(fn(Result(List(b), c)) -> t) -> t
Apply the given function to each item in a list, returning at first error.
pub fn try_or(
result: Result(a, b),
handle: fn(b) -> c,
then: fn(a) -> fn(fn(c) -> t) -> t,
) -> fn(fn(c) -> t) -> t
Work with results that are not continuations.