Current section
Files
Jump to
Current section
Files
src/agnostic@internals@mutable_map.erl
-module(agnostic@internals@mutable_map).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/agnostic/internals/mutable_map.gleam").
-export([new/0, unsafe_get/2, get_or_compute/3, has_key/2, insert/3, delete/2, size/1, is_empty/1]).
-export_type([mutable_map/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.
-type mutable_map(GPH, GPI) :: any() | {gleam_phantom, GPH, GPI}.
-file("src/agnostic/internals/mutable_map.gleam", 21).
?DOC("\n").
-spec new() -> mutable_map(any(), any()).
new() ->
maps:new().
-file("src/agnostic/internals/mutable_map.gleam", 26).
?DOC("\n").
-spec unsafe_get(mutable_map(GPN, GPO), GPN) -> GPO.
unsafe_get(Map, Key) ->
maps:get(Key, Map).
-file("src/agnostic/internals/mutable_map.gleam", 34).
-spec get_or_compute(mutable_map(GPV, GPW), GPV, fun(() -> GPW)) -> GPW.
get_or_compute(Map, Key, Compute) ->
case gleam@dict:get(Map, Key) of
{ok, Value} ->
Value;
_ ->
Compute()
end.
-file("src/agnostic/internals/mutable_map.gleam", 51).
?DOC("\n").
-spec has_key(mutable_map(GQF, any()), GQF) -> boolean().
has_key(Map, Key) ->
maps:is_key(Key, Map).
-file("src/agnostic/internals/mutable_map.gleam", 61).
?DOC("\n").
-spec insert(mutable_map(GQN, GQO), GQN, GQO) -> mutable_map(GQN, GQO).
insert(Map, Key, Value) ->
maps:put(Key, Value, Map).
-file("src/agnostic/internals/mutable_map.gleam", 79).
?DOC("\n").
-spec delete(mutable_map(GQZ, GRA), GQZ) -> mutable_map(GQZ, GRA).
delete(Map, Key) ->
maps:remove(Key, Map).
-file("src/agnostic/internals/mutable_map.gleam", 90).
?DOC("\n").
-spec size(mutable_map(any(), any())) -> integer().
size(Map) ->
maps:size(Map).
-file("src/agnostic/internals/mutable_map.gleam", 94).
?DOC("\n").
-spec is_empty(mutable_map(any(), any())) -> boolean().
is_empty(Map) ->
maps:size(Map) =:= 0.