decepticon

Types

The main type of this library- which represents a State wrapping a Result. See the decepticon/stateful module for standalone State

pub type StateResult(a, s, err) {
  StateResult(run: State(Result(a, err), s))
}

Constructors

  • StateResult(run: State(Result(a, err), s))

Functions

pub fn action(action_value: a) -> StateResult(a, b, c)

Lift a Result’s value argument into a StateResult

pub fn apply(
  prev: StateResult(fn(a) -> b, c, d),
  next: StateResult(a, c, d),
) -> StateResult(b, c, d)

Applicative Functor method for StateResult

pub fn do(
  over state_result: StateResult(a, b, c),
  with and_then_fn: fn(a) -> StateResult(d, b, c),
) -> StateResult(d, b, c)

The basic mechanism of chaining StateResult actions. This is most similar to result.try

pub fn error(error: a) -> StateResult(b, c, a)

Lift a Result’s error argument into a StateResult

pub fn error_state(state: State(a, b)) -> StateResult(c, b, a)

Lift a State type into a StateResult type. Wrapping it’s action type in result.Error

pub fn eval(
  state_result: StateResult(a, b, c),
  s: b,
) -> Result(a, c)

Given a StateResult, return the Result of the last executed action.

pub fn exec(state_result: StateResult(a, b, c), s: b) -> b

Given a StateResult, return the final version of the internal state.

pub fn get() -> StateResult(a, a, b)

Return the current value of state

pub fn map(
  over state_result: StateResult(a, b, c),
  with map_fn: fn(a) -> d,
) -> StateResult(d, b, c)

Map over the action type of a StateResult

pub fn map_error(
  over state_result: StateResult(a, b, c),
  with map_error_fn: fn(c) -> d,
) -> StateResult(a, b, d)

Map over the error type of a StateResult

pub fn ok_state(state: State(a, b)) -> StateResult(a, b, c)

Lift a State type into a StateResult type. Wrapping it’s action type in result.Ok

pub fn put(state_value: a) -> StateResult(Nil, a, b)

Set the current value of state

pub fn try(result_value: Result(a, b)) -> StateResult(a, c, b)

Lift a Result into the StateResult type. Useful for when you have a non-stateful action that is simply a Result and wish to weave it in as a use statement

Search Document