Current section

Files

Jump to
lustre src lustre@cmd.erl
Raw

src/lustre@cmd.erl

-module(lustre@cmd).
-compile(no_auto_import).
-export([from/1, none/0, batch/1, map/2, to_list/1]).
-export_type([cmd/1]).
-opaque cmd(FQV) :: {cmd, fun((fun((FQV) -> nil)) -> nil), cmd(FQV)} | none.
-spec from(fun((fun((FQW) -> nil)) -> nil)) -> cmd(FQW).
from(Cmd) ->
{cmd, Cmd, none}.
-spec none() -> cmd(any()).
none() ->
none.
-spec batch(list(cmd(FRA))) -> cmd(FRA).
batch(Cmds) ->
_pipe = Cmds,
_pipe@1 = gleam@list:flat_map(_pipe, fun to_list/1),
gleam@list:fold_right(_pipe@1, none, fun(Rest, Cmd) -> {cmd, Cmd, Rest} end).
-spec map(cmd(FRE), fun((FRE) -> FRG)) -> cmd(FRG).
map(Cmd, F) ->
case Cmd of
{cmd, Cmd@1, Next} ->
{cmd,
fun(Dispatch) -> Cmd@1(fun(A) -> Dispatch(F(A)) end) end,
map(Next, F)};
none ->
none
end.
-spec to_list(cmd(FRI)) -> list(fun((fun((FRI) -> nil)) -> nil)).
to_list(Cmd) ->
case Cmd of
{cmd, Cmd@1, Next} ->
[Cmd@1 | to_list(Next)];
none ->
[]
end.