Skip to content

Std.State

effect State[S]

Reads and writes a state of type S.

  • fn get() -> S

    The current state.

  • fn set(value: S) -> ()

    Sets the state to value.

  • fn update(f: fn(S) -> S) -> ()

    Applies f to the state. f is pure, so the update runs at once ([task.basic]).

fn run[S, A, E, R](initial: S, body: fn() -> A fails E uses { State[S], R }) -> (A, S) fails E uses { R }

Runs body with a state starting at initial, and returns the value of body paired with the final state. State[S] is removed from the R of body, so the call looks pure from outside. If body fails, the state is dropped and only the error propagates.