Current section
Files
Jump to
Current section
Files
src/go_over@util@util.erl
-module(go_over@util@util).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([iff/3, iff_nil/2, throwaway/2, hard_fail/2, freeze1/2, freeze2/3]).
-spec iff(boolean(), fun(() -> KOV), KOV) -> KOV.
iff(V, F, Default) ->
case V of
true ->
F();
_ ->
Default
end.
-spec iff_nil(boolean(), fun(() -> nil)) -> nil.
iff_nil(V, F) ->
iff(V, F, nil).
-spec throwaway(boolean(), fun(() -> {ok, any()} | {error, any()})) -> nil.
throwaway(V, F) ->
case V of
true ->
_ = F(),
nil;
_ ->
nil
end.
-spec hard_fail({ok, KPA} | {error, any()}, binary()) -> KPA.
hard_fail(Res, Msg) ->
case Res of
{ok, Val} ->
Val;
_ ->
go_over@util@print:warning(<<"Error: "/utf8, Msg/binary>>),
shellout_ffi:os_exit(1),
erlang:error(#{gleam_error => panic,
message => <<"unreachable"/utf8>>,
module => <<"go_over/util/util"/utf8>>,
function => <<"hard_fail"/utf8>>,
line => 32})
end.
-spec freeze1(fun((KPE) -> KPF), KPE) -> fun(() -> KPF).
freeze1(F, Arg) ->
fun() -> F(Arg) end.
-spec freeze2(fun((KPG, KPH) -> KPI), KPG, KPH) -> fun(() -> KPI).
freeze2(F, Arg1, Arg2) ->
fun() -> F(Arg1, Arg2) end.