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, inline]).
-define(FILEPATH, "src/gxyz/function.gleam").
-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(() -> FGH), FGH) -> FGH.
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", 32).
?DOC(
" freezes a value as an arity 0 function\n"
" freezes a value as an arity 0 function\n"
" ```\n"
": let x = function.freeze(1)\n"
": assert x() == 1\n"
": assert x() == 1\n"
" ```\n"
).
-spec freeze(FGM) -> fun(() -> FGM).
freeze(Value) ->
fun() -> Value end.
-file("src/gxyz/function.gleam", 37).
?DOC(" freezes an arity 1 function and it's arg as an arity 0 function\n").
-spec freeze1(fun((FGN) -> FGO), FGN) -> fun(() -> FGO).
freeze1(Fun, A) ->
fun() -> Fun(A) end.
-file("src/gxyz/function.gleam", 42).
?DOC(" freezes an arity 2 function and it's arg as an arity 0 function\n").
-spec freeze2(fun((FGQ, FGR) -> FGS), FGQ, FGR) -> fun(() -> FGS).
freeze2(Fun, A, B) ->
fun() -> Fun(A, B) end.
-file("src/gxyz/function.gleam", 47).
?DOC(" freezes an arity 3 function and it's arg as an arity 0 function\n").
-spec freeze3(fun((FGV, FGW, FGX) -> FGY), FGV, FGW, FGX) -> fun(() -> FGY).
freeze3(Fun, A, B, C) ->
fun() -> Fun(A, B, C) end.
-file("src/gxyz/function.gleam", 52).
?DOC(" freezes an arity 4 function and it's arg as an arity 0 function\n").
-spec freeze4(fun((FHC, FHD, FHE, FHF) -> FHG), FHC, FHD, FHE, FHF) -> fun(() -> FHG).
freeze4(Fun, A, B, C, D) ->
fun() -> Fun(A, B, C, D) end.
-file("src/gxyz/function.gleam", 57).
?DOC(" freezes an arity 5 function and it's arg as an arity 0 function\n").
-spec freeze5(fun((FHL, FHM, FHN, FHO, FHP) -> FHQ), FHL, FHM, FHN, FHO, FHP) -> fun(() -> FHQ).
freeze5(Fun, A, B, C, D, E) ->
fun() -> Fun(A, B, C, D, E) end.