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 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