midas/cont

Work with continuations as values.

Types

r is the final return type of the whole computation. a is the type of the value currently inside the monad.

pub type Cont(r, a) =
  fn(fn(a) -> r) -> r

Values

pub fn each(
  over list: List(a),
  with f: fn(a) -> fn(fn(b) -> r) -> r,
) -> fn(fn(List(b)) -> r) -> r

Apply a function to each value in a list in order

pub fn return(value: a) -> fn(fn(a) -> r) -> r

Create a continuation that returns the given value when called.

Often called pure.

pub fn then(
  cont: fn(fn(a) -> r) -> r,
  next: fn(a) -> fn(fn(b) -> r) -> r,
) -> fn(fn(b) -> r) -> r

compose two a continuation with a new function that returns another continuation

This is monad bind.

Search Document