act/state
Combining _state
functions with do
is so common that we have this simple
module to make things easier.
If you were previously writing actions like this:
import act.{do}
use state <- do(act.get_state())
use _ <- do(act.set_state("foo"))
use _ <- do(act.update_state(my_update_function))
Using the state
module you can write this instead:
import act/state
use state <- state.get()
use <- state.set("foo")
use <- state.update(my_update_function)
Ah, much better! The functions read very nicely and eliminate some visual complexity.
Functions
pub fn set(
state: a,
f: fn() -> fn(a) -> #(a, b),
) -> fn(a) -> #(a, b)
Equivalent of set_state
.
pub fn update(
updater: fn(a) -> a,
f: fn() -> fn(a) -> #(a, b),
) -> fn(a) -> #(a, b)
Equivalent of update_state
.