Packages

Compose stateful actions to simulate mutable state

Current section

Files

Jump to
act src act@state.erl
Raw

src/act@state.erl

-module(act@state).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([get/1, set/2, update/2]).
-spec get(fun((FST) -> fun((FST) -> {FST, FSU}))) -> fun((FST) -> {FST, FSU}).
get(F) ->
act:do(act:get_state(), F).
-spec set(FSZ, fun(() -> fun((FSZ) -> {FSZ, FTA}))) -> fun((FSZ) -> {FSZ, FTA}).
set(State, F) ->
act:do(act:set_state(State), fun(_) -> F() end).
-spec update(fun((FTF) -> FTF), fun(() -> fun((FTF) -> {FTF, FTG}))) -> fun((FTF) -> {FTF,
FTG}).
update(Updater, F) ->
act:do(act:update_state(Updater), fun(_) -> F() end).