Packages

🛒 A small library of helper functions, that works as a companion of gleam_stdlib

Current section

Files

Jump to
gxyz src gxyz@function.erl
Raw

src/gxyz@function.erl

-module(gxyz@function).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([iff/3, iff_nil/2, ignore_result/2, freeze/1, freeze1/2, freeze2/3, freeze3/4, freeze4/5, freeze5/6]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/gxyz/function.gleam", 2).
?DOC(" calls an arity 0 function if the condition is True, otherwise returns the default value\n").
-spec iff(boolean(), fun(() -> FRB), FRB) -> FRB.
iff(Condition, F, Default) ->
case Condition of
true ->
F();
_ ->
Default
end.
-file("src/gxyz/function.gleam", 10).
?DOC(" calls an arity 0 function if the condition is True, and returns Nil\n").
-spec iff_nil(boolean(), fun(() -> nil)) -> nil.
iff_nil(Condition, F) ->
iff(Condition, F, nil).
-file("src/gxyz/function.gleam", 15).
?DOC(" calls an arity 0 function if the condition is True, ignores the Result and returns Nil\n").
-spec ignore_result(boolean(), fun(() -> {ok, any()} | {error, any()})) -> nil.
ignore_result(Condition, F) ->
case Condition of
true ->
_ = F(),
nil;
_ ->
nil
end.
-file("src/gxyz/function.gleam", 26).
?DOC(" freezes a value as an arity 0 function\n").
-spec freeze(FRG) -> fun(() -> FRG).
freeze(Value) ->
fun() -> Value end.
-file("src/gxyz/function.gleam", 31).
?DOC(" freezes an arity 1 function and it's arg as an arity 0 function\n").
-spec freeze1(fun((FRH) -> FRI), FRH) -> fun(() -> FRI).
freeze1(Fun, A) ->
fun() -> Fun(A) end.
-file("src/gxyz/function.gleam", 36).
?DOC(" freezes an arity 2 function and it's arg as an arity 0 function\n").
-spec freeze2(fun((FRK, FRL) -> FRM), FRK, FRL) -> fun(() -> FRM).
freeze2(Fun, A, B) ->
fun() -> Fun(A, B) end.
-file("src/gxyz/function.gleam", 41).
?DOC(" freezes an arity 3 function and it's arg as an arity 0 function\n").
-spec freeze3(fun((FRP, FRQ, FRR) -> FRS), FRP, FRQ, FRR) -> fun(() -> FRS).
freeze3(Fun, A, B, C) ->
fun() -> Fun(A, B, C) end.
-file("src/gxyz/function.gleam", 46).
?DOC(" freezes an arity 4 function and it's arg as an arity 0 function\n").
-spec freeze4(fun((FRW, FRX, FRY, FRZ) -> FSA), FRW, FRX, FRY, FRZ) -> fun(() -> FSA).
freeze4(Fun, A, B, C, D) ->
fun() -> Fun(A, B, C, D) end.
-file("src/gxyz/function.gleam", 51).
?DOC(" freezes an arity 5 function and it's arg as an arity 0 function\n").
-spec freeze5(fun((FSF, FSG, FSH, FSI, FSJ) -> FSK), FSF, FSG, FSH, FSI, FSJ) -> fun(() -> FSK).
freeze5(Fun, A, B, C, D, E) ->
fun() -> Fun(A, B, C, D, E) end.