1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
-module(map).
-include_lib("eunit/include/eunit.hrl").
-export([new/0, size/1, to_list/1, from_list/1, fetch/2, map_values/2, keys/1, values/1, filter/2]).
new() ->
maps:new().
size(A) ->
maps:size(A).
to_list(A) ->
maps:to_list(A).
from_list(A) ->
maps:from_list(A).
-ifdef(TEST).
from_list_test() ->
Proplist = [{4, 0}, {1, 0}],
Map = from_list(Proplist),
_ = fun(Capture1) -> expect:equal(Capture1, 2) end(size(Map)),
fun(Capture1) -> expect:equal(Capture1, Proplist) end(to_list(Map)).
-endif.
fetch(A, B) ->
gleam__stdlib:map_fetch(A, B).
-ifdef(TEST).
fetch_test() ->
Proplist = [{4, 0}, {1, 1}],
Map = from_list(Proplist),
_ = fun(Capture1) ->
expect:equal(Capture1, {ok, 0})
end(fun(Capture1) -> fetch(Capture1, 4) end(Map)),
fun(Capture1) ->
expect:equal(Capture1, {ok, 1})
end(fun(Capture1) -> fetch(Capture1, 1) end(Map)).
-endif.
erl_map_values(A, B) ->
maps:map(A, B).
map_values(Map, Fun) ->
erl_map_values(Fun, Map).
-ifdef(TEST).
map_values_test() ->
fun(Capture1) ->
expect:equal(Capture1, from_list([{1, 0}, {2, 3}, {3, 5}]))
end(fun(Capture1) ->
map_values(Capture1, fun(K, V) -> K + V end)
end(from_list([{1, 0}, {2, 1}, {3, 2}]))).
-endif.
keys(A) ->
maps:keys(A).
-ifdef(TEST).
keys_test() ->
fun(Capture1) ->
expect:equal(Capture1, [<<"a">>, <<"b">>, <<"c">>])
end(keys(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))).
-endif.
values(A) ->
maps:values(A).
-ifdef(TEST).
values_test() ->
fun(Capture1) ->
expect:equal(Capture1, [0, 1, 2])
end(values(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))).
-endif.
erl_filter(A, B) ->
maps:filter(A, B).
filter(Map, Fun) ->
filter(Fun, Map).
|