Current section
Files
Jump to
Current section
Files
src/internal@context.erl
-module(internal@context).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/internal/context.gleam").
-export([erase/1, get_orelse/2, add_entry/2]).
-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/internal/context.gleam", 5).
?DOC(
" Erase the value referenced by `key`.\n"
"\n"
" Returns `True` if there was a value, `False` otherwise.\n"
).
-spec erase(binary()) -> boolean().
erase(Key) ->
context_ffi:ctx_erase(Key).
-file("src/internal/context.gleam", 18).
?DOC(" Retrieve the value referenced by `key` or `default` if not present.\n").
-spec get_orelse(binary(), REC) -> REC.
get_orelse(Key, Default) ->
case context_ffi:ctx_get(Key) of
{ok, A} ->
A;
{error, nil} ->
Default
end.
-file("src/internal/context.gleam", 29).
?DOC(
" Stores the `value` as referenced by `key` only if no value is already\n"
" present.\n"
"\n"
" This returns the stored value.\n"
).
-spec add_entry(binary(), any()) -> nil.
add_entry(Key, Value) ->
case context_ffi:ctx_get(Key) of
{error, nil} ->
context_ffi:ctx_add(Key, Value),
nil;
_ ->
nil
end.