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]).
-spec iff(boolean(), fun(() -> LWS), LWS) -> LWS.
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, LWX} | {error, any()}, binary()) -> LWX.
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.