docs / effects/state

effects/state

Effects

State

get ∀ 't0 . 't0 / { State<'t0> }
set fn(value: 't0) -> () / { State<'t0> }

Functions

state

fn ('t21, 't22 / 't20) -> 't22 / { 't20, -State<'t21>, -State<'t21> }

A handler for mutable state. Takes an initial value and threads state through get and set operations.

import core/effects/state { state, get, set }
let result = state(10) {
    let x = get();
    set(x + 5);
    get()
};
test.assert_eq(result, 15);