Current section

Files

Jump to
lustre src lustre@cli@utils.erl
Raw

src/lustre@cli@utils.erl

-module(lustre@cli@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export(['try'/3, replace/1, map/1, guard/3, 'when'/3]).
-spec 'try'(
{ok, NNE} | {error, NNF},
fun((NNF) -> NNI),
fun((NNE) -> {ok, NNL} | {error, NNI})
) -> {ok, NNL} | {error, NNI}.
'try'(Result, Strategy, F) ->
case Result of
{ok, Value} ->
F(Value);
{error, X} ->
{error, Strategy(X)}
end.
-spec replace(NNQ) -> fun((any()) -> NNQ).
replace(Error) ->
fun(_) -> Error end.
-spec map(fun((NNU) -> NNV)) -> fun((NNU) -> NNV).
map(F) ->
F.
-spec guard(boolean(), NNY, fun(() -> {ok, NNZ} | {error, NNY})) -> {ok, NNZ} |
{error, NNY}.
guard(Condition, Consequence, Then) ->
case Condition of
true ->
{error, Consequence};
false ->
Then()
end.
-spec 'when'(boolean(), NOE, fun(() -> {ok, NOE} | {error, NOF})) -> {ok, NOE} |
{error, NOF}.
'when'(Condition, Consequence, Then) ->
case Condition of
true ->
{ok, Consequence};
false ->
Then()
end.