-module(eval@context). -compile(no_auto_import). -export([get/0, set/1, modify/1, update/2]). -spec get() -> eval:eval(EXX, any(), EXX). get() -> eval:from(fun(Ctx) -> {Ctx, {ok, Ctx}} end). -spec set(EYC) -> eval:eval(nil, any(), EYC). set(Ctx) -> eval:from(fun(_) -> {Ctx, {ok, nil}} end). -spec modify(fun((EYH) -> EYH)) -> eval:eval(nil, any(), EYH). modify(F) -> _pipe = get(), eval:then(_pipe, fun(Ctx) -> set(F(Ctx)) end). -spec update(eval:eval(EYM, EYN, EYO), fun((EYO, EYM) -> EYO)) -> eval:eval(EYM, EYN, EYO). update(Eval, F) -> _pipe = eval:map2(Eval, get(), fun(A, Ctx) -> {Ctx, A} end), eval:then( _pipe, fun(Pair) -> {Ctx@1, A@1} = Pair, _pipe@1 = set(F(Ctx@1, A@1)), eval:map(_pipe@1, fun(_) -> A@1 end) end ).