Module Relude_StateT.WithMonad

Parameters

Signature

type t('a, 's) =
| StateT('s => M.t(('a, 's)))
;

StateT represents an effectful function from a state value of type 's to a result value 'a and a next state of type 's. This version of StateT has 'a on the left for consistency with other Reason types like Result/IO/Validation/etc.

let runStateT: s a. 's => t('a's) => M.t(('a, 's));

Applies an initial state value to run the StateT, producing the resulting value a and new state s in the result Monad.

let evalStateT: s a. t('a's) => 's => M.t('a);

Same as runStateT, but discards the final state, only returning the result a.

let execStateT: s a. t('a's) => 's => M.t('s);

Same as runStateT, but discards the final result a, only returning the final state s.

let mapStateT: s a b. (M.t(('a, 's)) => M.t(('b, 's))) => t('a's) => t('b's);

Change the result type in the StateT. Note: for simplicity, we don't allow changing the monad here.

let withStateT: s a. ('s => 's) => t('a's) => t('a's);

Modifies the state of a StateT

let get: s. t('s's);

Surfaces the current state as the result value a.

let gets: s a. ('s => 'a) => t('a's);

Extracts a value from the current state and surfaces it in the result value a.

let put: s. 's => t(unit, 's);

Overwrites the current state with a new state s.

let modify: s. ('s => 's) => t('s's);

Modifies the current state with a function, and also returns it in the result value a.

let modify_: s. ('s => 's) => t(unit, 's);

Same as modify, but doesn't return the new state as the result value a.

let map: s a b. ('a => 'b) => t('a's) => t('b's);
let pure: s a. 'a => t('a's);
let apply: s a b. t('a => 'b's) => t('a's) => t('b's);
let bind: s a b. t('a's) => ('a => t('b's)) => t('b's);
module WithState: (S: BsBastet.Interface.TYPE) => { ... };