aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gen/src/gleam@dynamic.erl4
-rw-r--r--gen/src/gleam@string.erl2
-rw-r--r--gen/test/gleam@atom_test.erl28
-rw-r--r--gen/test/gleam@dynamic_test.erl50
-rw-r--r--gen/test/gleam@float_test.erl19
-rw-r--r--gen/test/gleam@function_test.erl25
-rw-r--r--gen/test/gleam@int_test.erl22
-rw-r--r--gen/test/gleam@iodata_test.erl70
-rw-r--r--gen/test/gleam@list_test.erl14
-rw-r--r--gen/test/gleam@map_test.erl101
-rw-r--r--gen/test/gleam@pair_test.erl6
-rw-r--r--gen/test/gleam@result_test.erl17
-rw-r--r--gen/test/gleam@string_test.erl86
-rw-r--r--src/gleam/dynamic.gleam7
-rw-r--r--src/gleam/float.gleam2
-rw-r--r--src/gleam/map.gleam41
-rw-r--r--src/gleam/order.gleam1
-rw-r--r--src/gleam/pair.gleam2
-rw-r--r--src/gleam/result.gleam23
-rw-r--r--test/gleam/map_test.gleam7
20 files changed, 337 insertions, 190 deletions
diff --git a/gen/src/gleam@dynamic.erl b/gen/src/gleam@dynamic.erl
index 09a442b..d467820 100644
--- a/gen/src/gleam@dynamic.erl
+++ b/gen/src/gleam@dynamic.erl
@@ -33,7 +33,9 @@ list_dynamic(A) ->
list(Dynamic, DecoderType) ->
gleam@result:then(
list_dynamic(Dynamic),
- fun(Capture1) -> gleam@list:traverse(Capture1, DecoderType) end
+ fun(GleamCaptureVariable) ->
+ gleam@list:traverse(GleamCaptureVariable, DecoderType)
+ end
).
field(A, B) ->
diff --git a/gen/src/gleam@string.erl b/gen/src/gleam@string.erl
index 8cbfd1e..b8ee4e6 100644
--- a/gen/src/gleam@string.erl
+++ b/gen/src/gleam@string.erl
@@ -4,7 +4,7 @@
-export([is_empty/1, length/1, reverse/1, replace/3, lowercase/1, uppercase/1, compare/2, contains/2, split/2, append/2, concat/1, repeat/2, join/2]).
is_empty(Str) ->
- Str =:= <<"">>.
+ Str =:= <<""/utf8>>.
length(A) ->
string:length(A).
diff --git a/gen/test/gleam@atom_test.erl b/gen/test/gleam@atom_test.erl
index da1f699..91a16bd 100644
--- a/gen/test/gleam@atom_test.erl
+++ b/gen/test/gleam@atom_test.erl
@@ -4,38 +4,40 @@
-export([from_string_test/0, create_from_string_test/0, to_string_test/0]).
from_string_test() ->
- gleam@should:be_ok(gleam@atom:from_string(<<"ok">>)),
- gleam@should:be_ok(gleam@atom:from_string(<<"expect">>)),
+ gleam@should:be_ok(gleam@atom:from_string(<<"ok"/utf8>>)),
+ gleam@should:be_ok(gleam@atom:from_string(<<"expect"/utf8>>)),
gleam@should:equal(
- gleam@atom:from_string(<<"this is not an atom we have seen before">>),
+ gleam@atom:from_string(
+ <<"this is not an atom we have seen before"/utf8>>
+ ),
{error, atom_not_loaded}
).
create_from_string_test() ->
gleam@should:equal(
- {ok, gleam@atom:create_from_string(<<"ok">>)},
- gleam@atom:from_string(<<"ok">>)
+ {ok, gleam@atom:create_from_string(<<"ok"/utf8>>)},
+ gleam@atom:from_string(<<"ok"/utf8>>)
),
gleam@should:equal(
- {ok, gleam@atom:create_from_string(<<"expect">>)},
- gleam@atom:from_string(<<"expect">>)
+ {ok, gleam@atom:create_from_string(<<"expect"/utf8>>)},
+ gleam@atom:from_string(<<"expect"/utf8>>)
),
gleam@should:equal(
{ok,
gleam@atom:create_from_string(
- <<"this is another atom we have not seen before">>
+ <<"this is another atom we have not seen before"/utf8>>
)},
gleam@atom:from_string(
- <<"this is another atom we have not seen before">>
+ <<"this is another atom we have not seen before"/utf8>>
)
).
to_string_test() ->
gleam@should:equal(
- gleam@atom:to_string(gleam@atom:create_from_string(<<"ok">>)),
- <<"ok">>
+ gleam@atom:to_string(gleam@atom:create_from_string(<<"ok"/utf8>>)),
+ <<"ok"/utf8>>
),
gleam@should:equal(
- gleam@atom:to_string(gleam@atom:create_from_string(<<"expect">>)),
- <<"expect">>
+ gleam@atom:to_string(gleam@atom:create_from_string(<<"expect"/utf8>>)),
+ <<"expect"/utf8>>
).
diff --git a/gen/test/gleam@dynamic_test.erl b/gen/test/gleam@dynamic_test.erl
index 7cd1ba4..587b168 100644
--- a/gen/test/gleam@dynamic_test.erl
+++ b/gen/test/gleam@dynamic_test.erl
@@ -5,20 +5,20 @@
string_test() ->
gleam@should:equal(
- gleam@dynamic:string(gleam@dynamic:from(<<"">>)),
- {ok, <<"">>}
+ gleam@dynamic:string(gleam@dynamic:from(<<""/utf8>>)),
+ {ok, <<""/utf8>>}
),
gleam@should:equal(
- gleam@dynamic:string(gleam@dynamic:from(<<"Hello">>)),
- {ok, <<"Hello">>}
+ gleam@dynamic:string(gleam@dynamic:from(<<"Hello"/utf8>>)),
+ {ok, <<"Hello"/utf8>>}
),
gleam@should:equal(
gleam@dynamic:string(gleam@dynamic:from(1)),
- {error, <<"Expected a String, got `1`">>}
+ {error, <<"Expected a String, got `1`"/utf8>>}
),
gleam@should:equal(
gleam@dynamic:string(gleam@dynamic:from([])),
- {error, <<"Expected a String, got `[]`">>}
+ {error, <<"Expected a String, got `[]`"/utf8>>}
).
int_test() ->
@@ -26,11 +26,11 @@ int_test() ->
gleam@should:equal(gleam@dynamic:int(gleam@dynamic:from(2)), {ok, 2}),
gleam@should:equal(
gleam@dynamic:int(gleam@dynamic:from(1.0)),
- {error, <<"Expected an Int, got `1.0`">>}
+ {error, <<"Expected an Int, got `1.0`"/utf8>>}
),
gleam@should:equal(
gleam@dynamic:int(gleam@dynamic:from([])),
- {error, <<"Expected an Int, got `[]`">>}
+ {error, <<"Expected an Int, got `[]`"/utf8>>}
).
float_test() ->
@@ -38,11 +38,11 @@ float_test() ->
gleam@should:equal(gleam@dynamic:float(gleam@dynamic:from(2.2)), {ok, 2.2}),
gleam@should:equal(
gleam@dynamic:float(gleam@dynamic:from(1)),
- {error, <<"Expected a Float, got `1`">>}
+ {error, <<"Expected a Float, got `1`"/utf8>>}
),
gleam@should:equal(
gleam@dynamic:float(gleam@dynamic:from([])),
- {error, <<"Expected a Float, got `[]`">>}
+ {error, <<"Expected a Float, got `[]`"/utf8>>}
).
thunk_test() ->
@@ -71,25 +71,25 @@ bool_test() ->
),
gleam@should:equal(
gleam@dynamic:bool(gleam@dynamic:from(1)),
- {error, <<"Expected a Bool, got `1`">>}
+ {error, <<"Expected a Bool, got `1`"/utf8>>}
),
gleam@should:equal(
gleam@dynamic:bool(gleam@dynamic:from([])),
- {error, <<"Expected a Bool, got `[]`">>}
+ {error, <<"Expected a Bool, got `[]`"/utf8>>}
).
atom_test() ->
gleam@should:equal(
gleam@dynamic:atom(
- gleam@dynamic:from(gleam@atom:create_from_string(<<"">>))
+ gleam@dynamic:from(gleam@atom:create_from_string(<<""/utf8>>))
),
- {ok, gleam@atom:create_from_string(<<"">>)}
+ {ok, gleam@atom:create_from_string(<<""/utf8>>)}
),
gleam@should:equal(
gleam@dynamic:atom(
- gleam@dynamic:from(gleam@atom:create_from_string(<<"ok">>))
+ gleam@dynamic:from(gleam@atom:create_from_string(<<"ok"/utf8>>))
),
- {ok, gleam@atom:create_from_string(<<"ok">>)}
+ {ok, gleam@atom:create_from_string(<<"ok"/utf8>>)}
),
gleam@should:be_error(gleam@dynamic:atom(gleam@dynamic:from(1))),
gleam@should:be_error(gleam@dynamic:atom(gleam@dynamic:from([]))).
@@ -113,8 +113,11 @@ list_test() ->
gleam@should:equal(
gleam@dynamic:list(
gleam@dynamic:from([[1], [2], [3]]),
- fun(Capture1) ->
- gleam@dynamic:list(Capture1, fun gleam@dynamic:int/1)
+ fun(GleamCaptureVariable) ->
+ gleam@dynamic:list(
+ GleamCaptureVariable,
+ fun gleam@dynamic:int/1
+ )
end
),
{ok, [[1], [2], [3]]}
@@ -127,22 +130,23 @@ list_test() ->
),
gleam@should:be_error(
gleam@dynamic:list(
- gleam@dynamic:from([<<"">>]),
+ gleam@dynamic:from([<<""/utf8>>]),
fun gleam@dynamic:int/1
)
),
gleam@should:be_error(
gleam@dynamic:list(
gleam@dynamic:from(
- [gleam@dynamic:from(1), gleam@dynamic:from(<<"not an int">>)]
+ [gleam@dynamic:from(1),
+ gleam@dynamic:from(<<"not an int"/utf8>>)]
),
fun gleam@dynamic:int/1
)
).
field_test() ->
- {ok, OkAtom} = gleam@atom:from_string(<<"ok">>),
- {ok, ErrorAtom} = gleam@atom:from_string(<<"error">>),
+ {ok, OkAtom} = gleam@atom:from_string(<<"ok"/utf8>>),
+ {ok, ErrorAtom} = gleam@atom:from_string(<<"error"/utf8>>),
gleam@should:equal(
gleam@dynamic:field(
gleam@dynamic:from(gleam@map:insert(gleam@map:new(), OkAtom, 1)),
@@ -170,7 +174,7 @@ field_test() ->
gleam@should:be_error(gleam@dynamic:field(gleam@dynamic:from([]), [])).
element_test() ->
- {ok, OkAtom} = gleam@atom:from_string(<<"ok">>),
+ {ok, OkAtom} = gleam@atom:from_string(<<"ok"/utf8>>),
OkOneTuple = {OkAtom, 1},
gleam@should:equal(
gleam@dynamic:element(gleam@dynamic:from(OkOneTuple), 0),
diff --git a/gen/test/gleam@float_test.erl b/gen/test/gleam@float_test.erl
index f84f468..4f809c6 100644
--- a/gen/test/gleam@float_test.erl
+++ b/gen/test/gleam@float_test.erl
@@ -4,16 +4,19 @@
-export([parse_test/0, to_string_test/0, compare_test/0, ceiling_test/0, floor_test/0, round_test/0, truncate_test/0, min_test/0, max_test/0]).
parse_test() ->
- gleam@should:equal(gleam@float:parse(<<"1.23">>), {ok, 1.23}),
- gleam@should:equal(gleam@float:parse(<<"5.0">>), {ok, 5.0}),
- gleam@should:equal(gleam@float:parse(<<"0.123456789">>), {ok, 0.123456789}),
- gleam@should:equal(gleam@float:parse(<<"">>), {error, nil}),
- gleam@should:equal(gleam@float:parse(<<"what">>), {error, nil}),
- gleam@should:equal(gleam@float:parse(<<"1">>), {error, nil}).
+ gleam@should:equal(gleam@float:parse(<<"1.23"/utf8>>), {ok, 1.23}),
+ gleam@should:equal(gleam@float:parse(<<"5.0"/utf8>>), {ok, 5.0}),
+ gleam@should:equal(
+ gleam@float:parse(<<"0.123456789"/utf8>>),
+ {ok, 0.123456789}
+ ),
+ gleam@should:equal(gleam@float:parse(<<""/utf8>>), {error, nil}),
+ gleam@should:equal(gleam@float:parse(<<"what"/utf8>>), {error, nil}),
+ gleam@should:equal(gleam@float:parse(<<"1"/utf8>>), {error, nil}).
to_string_test() ->
- gleam@should:equal(gleam@float:to_string(123.0), <<"123.0">>),
- gleam@should:equal(gleam@float:to_string(-8.1), <<"-8.1">>).
+ gleam@should:equal(gleam@float:to_string(123.0), <<"123.0"/utf8>>),
+ gleam@should:equal(gleam@float:to_string(-8.1), <<"-8.1"/utf8>>).
compare_test() ->
gleam@should:equal(gleam@float:compare(0.0, 0.0), eq),
diff --git a/gen/test/gleam@function_test.erl b/gen/test/gleam@function_test.erl
index ecac21f..d85bce1 100644
--- a/gen/test/gleam@function_test.erl
+++ b/gen/test/gleam@function_test.erl
@@ -11,35 +11,40 @@ compose_test() ->
HeadToString = gleam@function:compose(
gleam@function:compose(
fun gleam@list:head/1,
- fun(Capture1) -> gleam@result:unwrap(Capture1, 0) end
+ fun(GleamCaptureVariable) ->
+ gleam@result:unwrap(GleamCaptureVariable, 0)
+ end
),
fun gleam@int:to_string/1
),
- gleam@should:equal(HeadToString([1]), <<"1">>),
- gleam@should:equal(HeadToString([]), <<"0">>).
+ gleam@should:equal(HeadToString([1]), <<"1"/utf8>>),
+ gleam@should:equal(HeadToString([]), <<"0"/utf8>>).
flip_test() ->
Fun = fun(S, I) ->
gleam@string:append(
gleam@string:append(
gleam@string:append(
- gleam@string:append(<<"String: '">>, S),
- <<"', Int: '">>
+ gleam@string:append(<<"String: '"/utf8>>, S),
+ <<"', Int: '"/utf8>>
),
gleam@int:to_string(I)
),
- <<"'">>
+ <<"'"/utf8>>
)
end,
FlippedFun = gleam@function:flip(Fun),
- gleam@should:equal(Fun(<<"Bob">>, 1), <<"String: 'Bob', Int: '1'">>),
gleam@should:equal(
- FlippedFun(2, <<"Alice">>),
- <<"String: 'Alice', Int: '2'">>
+ Fun(<<"Bob"/utf8>>, 1),
+ <<"String: 'Bob', Int: '1'"/utf8>>
+ ),
+ gleam@should:equal(
+ FlippedFun(2, <<"Alice"/utf8>>),
+ <<"String: 'Alice', Int: '2'"/utf8>>
).
identity_test() ->
gleam@should:equal(gleam@function:identity(1), 1),
- gleam@should:equal(gleam@function:identity(<<"">>), <<"">>),
+ gleam@should:equal(gleam@function:identity(<<""/utf8>>), <<""/utf8>>),
gleam@should:equal(gleam@function:identity([]), []),
gleam@should:equal(gleam@function:identity({1, 2.0}), {1, 2.0}).
diff --git a/gen/test/gleam@int_test.erl b/gen/test/gleam@int_test.erl
index 1a6c8c2..d1f17b0 100644
--- a/gen/test/gleam@int_test.erl
+++ b/gen/test/gleam@int_test.erl
@@ -4,21 +4,21 @@
-export([to_string/0, parse/0, to_base_string/0, compare_test/0, min_test/0, max_test/0, is_even_test/0, is_odd_test/0]).
to_string() ->
- gleam@should:equal(gleam@int:to_string(123), <<"123">>),
- gleam@should:equal(gleam@int:to_string(-123), <<"-123">>),
- gleam@should:equal(gleam@int:to_string(123), <<"123">>).
+ gleam@should:equal(gleam@int:to_string(123), <<"123"/utf8>>),
+ gleam@should:equal(gleam@int:to_string(-123), <<"-123"/utf8>>),
+ gleam@should:equal(gleam@int:to_string(123), <<"123"/utf8>>).
parse() ->
- gleam@should:equal(gleam@int:parse(<<"123">>), {ok, 123}),
- gleam@should:equal(gleam@int:parse(<<"-123">>), {ok, -123}),
- gleam@should:equal(gleam@int:parse(<<"0123">>), {ok, 123}),
- gleam@should:equal(gleam@int:parse(<<"">>), {error, nil}),
- gleam@should:equal(gleam@int:parse(<<"what">>), {error, nil}),
- gleam@should:equal(gleam@int:parse(<<"1.23">>), {error, nil}).
+ gleam@should:equal(gleam@int:parse(<<"123"/utf8>>), {ok, 123}),
+ gleam@should:equal(gleam@int:parse(<<"-123"/utf8>>), {ok, -123}),
+ gleam@should:equal(gleam@int:parse(<<"0123"/utf8>>), {ok, 123}),
+ gleam@should:equal(gleam@int:parse(<<""/utf8>>), {error, nil}),
+ gleam@should:equal(gleam@int:parse(<<"what"/utf8>>), {error, nil}),
+ gleam@should:equal(gleam@int:parse(<<"1.23"/utf8>>), {error, nil}).
to_base_string() ->
- gleam@should:equal(gleam@int:to_base_string(100, 16), <<"64">>),
- gleam@should:equal(gleam@int:to_base_string(-100, 16), <<"-64">>).
+ gleam@should:equal(gleam@int:to_base_string(100, 16), <<"64"/utf8>>),
+ gleam@should:equal(gleam@int:to_base_string(-100, 16), <<"-64"/utf8>>).
compare_test() ->
gleam@should:equal(gleam@int:compare(0, 0), eq),
diff --git a/gen/test/gleam@iodata_test.erl b/gen/test/gleam@iodata_test.erl
index 63cec0b..3df2cbb 100644
--- a/gen/test/gleam@iodata_test.erl
+++ b/gen/test/gleam@iodata_test.erl
@@ -6,88 +6,98 @@
iodata_test() ->
Data = gleam@iodata:prepend(
gleam@iodata:append(
- gleam@iodata:append(gleam@iodata:new(<<"ello">>), <<",">>),
- <<" world!">>
+ gleam@iodata:append(gleam@iodata:new(<<"ello"/utf8>>), <<","/utf8>>),
+ <<" world!"/utf8>>
),
- <<"H">>
+ <<"H"/utf8>>
),
- gleam@should:equal(gleam@iodata:to_string(Data), <<"Hello, world!">>),
+ gleam@should:equal(gleam@iodata:to_string(Data), <<"Hello, world!"/utf8>>),
gleam@should:equal(gleam@iodata:byte_size(Data), 13),
Data1 = gleam@iodata:prepend_iodata(
gleam@iodata:append_iodata(
gleam@iodata:append_iodata(
- gleam@iodata:new(<<"ello">>),
- gleam@iodata:new(<<",">>)
+ gleam@iodata:new(<<"ello"/utf8>>),
+ gleam@iodata:new(<<","/utf8>>)
),
gleam@iodata:concat(
- [gleam@iodata:new(<<" wo">>), gleam@iodata:new(<<"rld!">>)]
+ [gleam@iodata:new(<<" wo"/utf8>>),
+ gleam@iodata:new(<<"rld!"/utf8>>)]
)
),
- gleam@iodata:new(<<"H">>)
+ gleam@iodata:new(<<"H"/utf8>>)
),
- gleam@should:equal(gleam@iodata:to_string(Data1), <<"Hello, world!">>),
+ gleam@should:equal(gleam@iodata:to_string(Data1), <<"Hello, world!"/utf8>>),
gleam@should:equal(gleam@iodata:byte_size(Data1), 13).
lowercase_test() ->
gleam@should:equal(
gleam@iodata:to_string(
gleam@iodata:lowercase(
- gleam@iodata:from_strings([<<"Gleam">>, <<"Gleam">>])
+ gleam@iodata:from_strings([<<"Gleam"/utf8>>, <<"Gleam"/utf8>>])
)
),
- <<"gleamgleam">>
+ <<"gleamgleam"/utf8>>
).
uppercase_test() ->
gleam@should:equal(
gleam@iodata:to_string(
gleam@iodata:uppercase(
- gleam@iodata:from_strings([<<"Gleam">>, <<"Gleam">>])
+ gleam@iodata:from_strings([<<"Gleam"/utf8>>, <<"Gleam"/utf8>>])
)
),
- <<"GLEAMGLEAM">>
+ <<"GLEAMGLEAM"/utf8>>
).
split_test() ->
gleam@should:equal(
- gleam@iodata:split(gleam@iodata:new(<<"Gleam,Erlang,Elixir">>), <<",">>),
- [gleam@iodata:new(<<"Gleam">>),
- gleam@iodata:new(<<"Erlang">>),
- gleam@iodata:new(<<"Elixir">>)]
+ gleam@iodata:split(
+ gleam@iodata:new(<<"Gleam,Erlang,Elixir"/utf8>>),
+ <<","/utf8>>
+ ),
+ [gleam@iodata:new(<<"Gleam"/utf8>>),
+ gleam@iodata:new(<<"Erlang"/utf8>>),
+ gleam@iodata:new(<<"Elixir"/utf8>>)]
),
gleam@should:equal(
gleam@iodata:split(
- gleam@iodata:from_strings([<<"Gleam, Erl">>, <<"ang,Elixir">>]),
- <<", ">>
+ gleam@iodata:from_strings(
+ [<<"Gleam, Erl"/utf8>>, <<"ang,Elixir"/utf8>>]
+ ),
+ <<", "/utf8>>
),
- [gleam@iodata:new(<<"Gleam">>),
- gleam@iodata:from_strings([<<"Erl">>, <<"ang,Elixir">>])]
+ [gleam@iodata:new(<<"Gleam"/utf8>>),
+ gleam@iodata:from_strings([<<"Erl"/utf8>>, <<"ang,Elixir"/utf8>>])]
).
is_equal_test() ->
gleam@should:be_true(
gleam@iodata:is_equal(
- gleam@iodata:new(<<"12">>),
- gleam@iodata:from_strings([<<"1">>, <<"2">>])
+ gleam@iodata:new(<<"12"/utf8>>),
+ gleam@iodata:from_strings([<<"1"/utf8>>, <<"2"/utf8>>])
)
),
gleam@should:be_true(
gleam@iodata:is_equal(
- gleam@iodata:new(<<"12">>),
- gleam@iodata:new(<<"12">>)
+ gleam@iodata:new(<<"12"/utf8>>),
+ gleam@iodata:new(<<"12"/utf8>>)
)
),
gleam@should:be_false(
gleam@iodata:is_equal(
- gleam@iodata:new(<<"12">>),
- gleam@iodata:new(<<"2">>)
+ gleam@iodata:new(<<"12"/utf8>>),
+ gleam@iodata:new(<<"2"/utf8>>)
)
).
is_empty_test() ->
- gleam@should:be_true(gleam@iodata:is_empty(gleam@iodata:new(<<"">>))),
- gleam@should:be_false(gleam@iodata:is_empty(gleam@iodata:new(<<"12">>))),
+ gleam@should:be_true(gleam@iodata:is_empty(gleam@iodata:new(<<""/utf8>>))),
+ gleam@should:be_false(
+ gleam@iodata:is_empty(gleam@iodata:new(<<"12"/utf8>>))
+ ),
gleam@should:be_true(gleam@iodata:is_empty(gleam@iodata:from_strings([]))),
gleam@should:be_true(
- gleam@iodata:is_empty(gleam@iodata:from_strings([<<"">>, <<"">>]))
+ gleam@iodata:is_empty(
+ gleam@iodata:from_strings([<<""/utf8>>, <<""/utf8>>])
+ )
).
diff --git a/gen/test/gleam@list_test.erl b/gen/test/gleam@list_test.erl
index 5f6fcfb..a49a26f 100644
--- a/gen/test/gleam@list_test.erl
+++ b/gen/test/gleam@list_test.erl
@@ -218,8 +218,8 @@ index_map_test() ->
),
F = fun(I1, X1) -> gleam@string:append(X1, gleam@int:to_string(I1)) end,
gleam@should:equal(
- gleam@list:index_map([<<"a">>, <<"b">>, <<"c">>], F),
- [<<"a0">>, <<"b1">>, <<"c2">>]
+ gleam@list:index_map([<<"a"/utf8>>, <<"b"/utf8>>, <<"c"/utf8>>], F),
+ [<<"a0"/utf8>>, <<"b1"/utf8>>, <<"c2"/utf8>>]
).
range_test() ->
@@ -235,8 +235,8 @@ repeat_test() ->
gleam@should:equal(gleam@list:repeat(1, 0), []),
gleam@should:equal(gleam@list:repeat(2, 3), [2, 2, 2]),
gleam@should:equal(
- gleam@list:repeat(<<"x">>, 5),
- [<<"x">>, <<"x">>, <<"x">>, <<"x">>, <<"x">>]
+ gleam@list:repeat(<<"x"/utf8>>, 5),
+ [<<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>]
).
split_test() ->
@@ -285,7 +285,7 @@ split_while_test() ->
).
key_find_test() ->
- Proplist = [{0, <<"1">>}, {1, <<"2">>}],
- gleam@should:equal(gleam@list:key_find(Proplist, 0), {ok, <<"1">>}),
- gleam@should:equal(gleam@list:key_find(Proplist, 1), {ok, <<"2">>}),
+ Proplist = [{0, <<"1"/utf8>>}, {1, <<"2"/utf8>>}],
+ gleam@should:equal(gleam@list:key_find(Proplist, 0), {ok, <<"1"/utf8>>}),
+ gleam@should:equal(gleam@list:key_find(Proplist, 1), {ok, <<"2"/utf8>>}),
gleam@should:equal(gleam@list:key_find(Proplist, 2), {error, nil}).
diff --git a/gen/test/gleam@map_test.erl b/gen/test/gleam@map_test.erl
index 7c97524..4729edf 100644
--- a/gen/test/gleam@map_test.erl
+++ b/gen/test/gleam@map_test.erl
@@ -7,6 +7,10 @@ from_list_test() ->
gleam@should:equal(
gleam@map:size(gleam@map:from_list([{4, 0}, {1, 0}])),
2
+ ),
+ gleam@should:equal(
+ gleam@map:from_list([{1, 0}, {1, 1}]),
+ gleam@map:from_list([{1, 1}])
).
has_key_test() ->
@@ -34,14 +38,16 @@ insert_test() ->
gleam@should:equal(
gleam@map:insert(
gleam@map:insert(
- gleam@map:insert(gleam@map:new(), <<"a">>, 0),
- <<"b">>,
+ gleam@map:insert(gleam@map:new(), <<"a"/utf8>>, 0),
+ <<"b"/utf8>>,
1
),
- <<"c">>,
+ <<"c"/utf8>>,
2
),
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}])
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ )
).
map_values_test() ->
@@ -56,15 +62,19 @@ map_values_test() ->
keys_test() ->
gleam@should:equal(
gleam@map:keys(
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}])
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ )
),
- [<<"a">>, <<"b">>, <<"c">>]
+ [<<"a"/utf8>>, <<"b"/utf8>>, <<"c"/utf8>>]
).
values_test() ->
gleam@should:equal(
gleam@map:values(
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}])
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ )
),
[0, 1, 2]
).
@@ -72,34 +82,48 @@ values_test() ->
take_test() ->
gleam@should:equal(
gleam@map:take(
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]),
- [<<"a">>, <<"b">>, <<"d">>]
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ ),
+ [<<"a"/utf8>>, <<"b"/utf8>>, <<"d"/utf8>>]
),
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}])
+ gleam@map:from_list([{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}])
).
drop_test() ->
gleam@should:equal(
gleam@map:drop(
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]),
- [<<"a">>, <<"b">>, <<"d">>]
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ ),
+ [<<"a"/utf8>>, <<"b"/utf8>>, <<"d"/utf8>>]
),
- gleam@map:from_list([{<<"c">>, 2}])
+ gleam@map:from_list([{<<"c"/utf8>>, 2}])
).
merge_test() ->
- A = gleam@map:from_list([{<<"a">>, 2}, {<<"c">>, 4}, {<<"d">>, 3}]),
- B = gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]),
+ A = gleam@map:from_list(
+ [{<<"a"/utf8>>, 2}, {<<"c"/utf8>>, 4}, {<<"d"/utf8>>, 3}]
+ ),
+ B = gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ ),
gleam@should:equal(
gleam@map:merge(A, B),
gleam@map:from_list(
- [{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}, {<<"d">>, 3}]
+ [{<<"a"/utf8>>, 0},
+ {<<"b"/utf8>>, 1},
+ {<<"c"/utf8>>, 2},
+ {<<"d"/utf8>>, 3}]
)
),
gleam@should:equal(
gleam@map:merge(B, A),
gleam@map:from_list(
- [{<<"a">>, 2}, {<<"b">>, 1}, {<<"c">>, 4}, {<<"d">>, 3}]
+ [{<<"a"/utf8>>, 2},
+ {<<"b"/utf8>>, 1},
+ {<<"c"/utf8>>, 4},
+ {<<"d"/utf8>>, 3}]
)
).
@@ -107,16 +131,20 @@ delete_test() ->
gleam@should:equal(
gleam@map:delete(
gleam@map:delete(
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]),
- <<"a">>
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ ),
+ <<"a"/utf8>>
),
- <<"d">>
+ <<"d"/utf8>>
),
- gleam@map:from_list([{<<"b">>, 1}, {<<"c">>, 2}])
+ gleam@map:from_list([{<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}])
).
update_test() ->
- Dict = gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]),
+ Dict = gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ ),
IncOrZero = fun(X) -> case X of
{ok, I} ->
I + 1;
@@ -125,26 +153,39 @@ update_test() ->
0
end end,
gleam@should:equal(
- gleam@map:update(Dict, <<"a">>, IncOrZero),
- gleam@map:from_list([{<<"a">>, 1}, {<<"b">>, 1}, {<<"c">>, 2}])
+ gleam@map:update(Dict, <<"a"/utf8>>, IncOrZero),
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 1}, {<<"b"/utf8>>, 1}, {<<"c"/utf8>>, 2}]
+ )
),
gleam@should:equal(
- gleam@map:update(Dict, <<"b">>, IncOrZero),
- gleam@map:from_list([{<<"a">>, 0}, {<<"b">>, 2}, {<<"c">>, 2}])
+ gleam@map:update(Dict, <<"b"/utf8>>, IncOrZero),
+ gleam@map:from_list(
+ [{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 2}, {<<"c"/utf8>>, 2}]
+ )
),
gleam@should:equal(
- gleam@map:update(Dict, <<"z">>, IncOrZero),
+ gleam@map:update(Dict, <<"z"/utf8>>, IncOrZero),
gleam@map:from_list(
- [{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}, {<<"z">>, 0}]
+ [{<<"a"/utf8>>, 0},
+ {<<"b"/utf8>>, 1},
+ {<<"c"/utf8>>, 2},
+ {<<"z"/utf8>>, 0}]
)
).
fold_test() ->
Dict = gleam@map:from_list(
- [{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}, {<<"d">>, 3}]
+ [{<<"a"/utf8>>, 0},
+ {<<"b"/utf8>>, 1},
+ {<<"c"/utf8>>, 2},
+ {<<"d"/utf8>>, 3}]
),
Add = fun(_, V, Acc) -> V + Acc end,
gleam@should:equal(gleam@map:fold(Dict, 0, Add), 6),
Concat = fun(K, _, Acc1) -> gleam@string:append(Acc1, K) end,
- gleam@should:equal(gleam@map:fold(Dict, <<"">>, Concat), <<"abcd">>),
+ gleam@should:equal(
+ gleam@map:fold(Dict, <<""/utf8>>, Concat),
+ <<"abcd"/utf8>>
+ ),
gleam@should:equal(gleam@map:fold(gleam@map:from_list([]), 0, Add), 0).
diff --git a/gen/test/gleam@pair_test.erl b/gen/test/gleam@pair_test.erl
index f1addd4..d073e19 100644
--- a/gen/test/gleam@pair_test.erl
+++ b/gen/test/gleam@pair_test.erl
@@ -5,14 +5,14 @@
first_test() ->
gleam@should:equal(gleam@pair:first({1, 2}), 1),
- gleam@should:equal(gleam@pair:first({<<"abc">>, []}), <<"abc">>).
+ gleam@should:equal(gleam@pair:first({<<"abc"/utf8>>, []}), <<"abc"/utf8>>).
second_test() ->
gleam@should:equal(gleam@pair:second({1, 2}), 2),
- gleam@should:equal(gleam@pair:second({<<"abc">>, []}), []).
+ gleam@should:equal(gleam@pair:second({<<"abc"/utf8>>, []}), []).
swap_test() ->
- gleam@should:equal(gleam@pair:swap({1, <<"2">>}), {<<"2">>, 1}).
+ gleam@should:equal(gleam@pair:swap({1, <<"2"/utf8>>}), {<<"2"/utf8>>, 1}).
map_first_test() ->
Inc = fun(A) -> A + 1 end,
diff --git a/gen/test/gleam@result_test.erl b/gen/test/gleam@result_test.erl
index 4c3b270..b40d41d 100644
--- a/gen/test/gleam@result_test.erl
+++ b/gen/test/gleam@result_test.erl
@@ -14,8 +14,8 @@ is_error_test() ->
map_test() ->
gleam@should:equal(gleam@result:map({ok, 1}, fun(X) -> X + 1 end), {ok, 2}),
gleam@should:equal(
- gleam@result:map({ok, 1}, fun(_) -> <<"2">> end),
- {ok, <<"2">>}
+ gleam@result:map({ok, 1}, fun(_) -> <<"2"/utf8>> end),
+ {ok, <<"2"/utf8>>}
),
gleam@should:equal(
gleam@result:map({error, 1}, fun(X1) -> X1 + 1 end),
@@ -28,8 +28,11 @@ map_error_test() ->
{ok, 1}
),
gleam@should:equal(
- gleam@result:map_error({error, 1}, fun(X1) -> {<<"ok">>, X1 + 1} end),
- {error, {<<"ok">>, 2}}
+ gleam@result:map_error(
+ {error, 1},
+ fun(X1) -> {<<"ok"/utf8>>, X1 + 1} end
+ ),
+ {error, {<<"ok"/utf8>>, 2}}
).
flatten_test() ->
@@ -51,8 +54,8 @@ then_test() ->
{ok, 2}
),
gleam@should:equal(
- gleam@result:then({ok, 1}, fun(_) -> {ok, <<"type change">>} end),
- {ok, <<"type change">>}
+ gleam@result:then({ok, 1}, fun(_) -> {ok, <<"type change"/utf8>>} end),
+ {ok, <<"type change"/utf8>>}
),
gleam@should:equal(
gleam@result:then({ok, 1}, fun(_) -> {error, 1} end),
@@ -61,4 +64,4 @@ then_test() ->
unwrap_test() ->
gleam@should:equal(gleam@result:unwrap({ok, 1}, 50), 1),
- gleam@should:equal(gleam@result:unwrap({error, <<"nope">>}, 50), 50).
+ gleam@should:equal(gleam@result:unwrap({error, <<"nope"/utf8>>}, 50), 50).
diff --git a/gen/test/gleam@string_test.erl b/gen/test/gleam@string_test.erl
index 603ff1c..c6e423e 100644
--- a/gen/test/gleam@string_test.erl
+++ b/gen/test/gleam@string_test.erl
@@ -4,73 +4,97 @@
-export([length_test/0, lowercase_test/0, uppercase_test/0, reverse_test/0, split_test/0, replace_test/0, append_test/0, compare_test/0, contains_test/0, concat_test/0, repeat_test/0, join_test/0]).
length_test() ->
- gleam@should:equal(gleam@string:length(<<"ß↑e̊">>), 3),
- gleam@should:equal(gleam@string:length(<<"Gleam">>), 5),
- gleam@should:equal(gleam@string:length(<<"">>), 0).
+ gleam@should:equal(gleam@string:length(<<"ß↑e̊"/utf8>>), 3),
+ gleam@should:equal(gleam@string:length(<<"Gleam"/utf8>>), 5),
+ gleam@should:equal(gleam@string:length(<<""/utf8>>), 0).
lowercase_test() ->
- gleam@should:equal(gleam@string:lowercase(<<"Gleam">>), <<"gleam">>).
+ gleam@should:equal(
+ gleam@string:lowercase(<<"Gleam"/utf8>>),
+ <<"gleam"/utf8>>
+ ).
uppercase_test() ->
- gleam@should:equal(gleam@string:uppercase(<<"Gleam">>), <<"GLEAM">>).
+ gleam@should:equal(
+ gleam@string:uppercase(<<"Gleam"/utf8>>),
+ <<"GLEAM"/utf8>>
+ ).
reverse_test() ->
- gleam@should:equal(gleam@string:reverse(<<"Gleam">>), <<"maelG">>).
+ gleam@should:equal(
+ gleam@string:reverse(<<"Gleam"/utf8>>),
+ <<"maelG"/utf8>>
+ ).
split_test() ->
gleam@should:equal(
- gleam@string:split(<<"Gleam,Erlang,Elixir">>, <<",">>),
- [<<"Gleam">>, <<"Erlang">>, <<"Elixir">>]
+ gleam@string:split(<<"Gleam,Erlang,Elixir"/utf8>>, <<","/utf8>>),
+ [<<"Gleam"/utf8>>, <<"Erlang"/utf8>>, <<"Elixir"/utf8>>]
),
gleam@should:equal(
- gleam@string:split(<<"Gleam, Erlang,Elixir">>, <<", ">>),
- [<<"Gleam">>, <<"Erlang,Elixir">>]
+ gleam@string:split(<<"Gleam, Erlang,Elixir"/utf8>>, <<", "/utf8>>),
+ [<<"Gleam"/utf8>>, <<"Erlang,Elixir"/utf8>>]
).
replace_test() ->
gleam@should:equal(
- gleam@string:replace(<<"Gleam,Erlang,Elixir">>, <<",">>, <<"++">>),
- <<"Gleam++Erlang++Elixir">>
+ gleam@string:replace(
+ <<"Gleam,Erlang,Elixir"/utf8>>,
+ <<","/utf8>>,
+ <<"++"/utf8>>
+ ),
+ <<"Gleam++Erlang++Elixir"/utf8>>
).
append_test() ->
gleam@should:equal(
- gleam@string:append(<<"Test">>, <<" Me">>),
- <<"Test Me">>
+ gleam@string:append(<<"Test"/utf8>>, <<" Me"/utf8>>),
+ <<"Test Me"/utf8>>
).
compare_test() ->
- gleam@should:equal(gleam@string:compare(<<"">>, <<"">>), eq),
- gleam@should:equal(gleam@string:compare(<<"a">>, <<"">>), gt),
- gleam@should:equal(gleam@string:compare(<<"a">>, <<"A">>), gt),
- gleam@should:equal(gleam@string:compare(<<"A">>, <<"B">>), lt),
- gleam@should:equal(gleam@string:compare(<<"t">>, <<"ABC">>), gt).
+ gleam@should:equal(gleam@string:compare(<<""/utf8>>, <<""/utf8>>), eq),
+ gleam@should:equal(gleam@string:compare(<<"a"/utf8>>, <<""/utf8>>), gt),
+ gleam@should:equal(gleam@string:compare(<<"a"/utf8>>, <<"A"/utf8>>), gt),
+ gleam@should:equal(gleam@string:compare(<<"A"/utf8>>, <<"B"/utf8>>), lt),
+ gleam@should:equal(gleam@string:compare(<<"t"/utf8>>, <<"ABC"/utf8>>), gt).
contains_test() ->
- gleam@should:equal(gleam@string:contains(<<"gleam">>, <<"ea">>), true),
- gleam@should:equal(gleam@string:contains(<<"gleam">>, <<"x">>), false),
gleam@should:equal(
- gleam@string:contains(<<"bellwether">>, <<"bell">>),
+ gleam@string:contains(<<"gleam"/utf8>>, <<"ea"/utf8>>),
+ true
+ ),
+ gleam@should:equal(
+ gleam@string:contains(<<"gleam"/utf8>>, <<"x"/utf8>>),
+ false
+ ),
+ gleam@should:equal(
+ gleam@string:contains(<<"bellwether"/utf8>>, <<"bell"/utf8>>),
true
).
concat_test() ->
gleam@should:equal(
- gleam@string:concat([<<"Hello">>, <<", ">>, <<"world!">>]),
- <<"Hello, world!">>
+ gleam@string:concat(
+ [<<"Hello"/utf8>>, <<", "/utf8>>, <<"world!"/utf8>>]
+ ),
+ <<"Hello, world!"/utf8>>
).
repeat_test() ->
- gleam@should:equal(gleam@string:repeat(<<"hi">>, 3), <<"hihihi">>),
- gleam@should:equal(gleam@string:repeat(<<"hi">>, 0), <<"">>),
- gleam@should:equal(gleam@string:repeat(<<"hi">>, -1), <<"">>).
+ gleam@should:equal(
+ gleam@string:repeat(<<"hi"/utf8>>, 3),
+ <<"hihihi"/utf8>>
+ ),
+ gleam@should:equal(gleam@string:repeat(<<"hi"/utf8>>, 0), <<""/utf8>>),
+ gleam@should:equal(gleam@string:repeat(<<"hi"/utf8>>, -1), <<""/utf8>>).
join_test() ->
gleam@should:equal(
- gleam@string:join([<<"Hello">>, <<"world!">>], <<", ">>),
- <<"Hello, world!">>
+ gleam@string:join([<<"Hello"/utf8>>, <<"world!"/utf8>>], <<", "/utf8>>),
+ <<"Hello, world!"/utf8>>
),
gleam@should:equal(
- gleam@string:join([<<"Hello">>, <<"world!">>], <<"-">>),
- <<"Hello-world!">>
+ gleam@string:join([<<"Hello"/utf8>>, <<"world!"/utf8>>], <<"-"/utf8>>),
+ <<"Hello-world!"/utf8>>
).
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam
index 6bddfdf..0e54ae1 100644
--- a/src/gleam/dynamic.gleam
+++ b/src/gleam/dynamic.gleam
@@ -1,11 +1,10 @@
-/// `Dynamic` data is data that we don"t know the type of yet.
-/// We likely get data like this from interop with Erlang, or from
-/// IO with the outside world.
-
import gleam/list as list_mod
import gleam/atom
import gleam/result
+/// `Dynamic` data is data that we don"t know the type of yet.
+/// We likely get data like this from interop with Erlang, or from
+/// IO with the outside world.
pub external type Dynamic;
/// Convert any Gleam data into `Dynamic` data.
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam
index 9de1549..b02cd94 100644
--- a/src/gleam/float.gleam
+++ b/src/gleam/float.gleam
@@ -1,5 +1,3 @@
-/// A set of utility functions for working with `Float` values.
-
import gleam/iodata
import gleam/order.{Order}
import gleam/result.{Option}
diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam
index 0b5595c..9762cd0 100644
--- a/src/gleam/map.gleam
+++ b/src/gleam/map.gleam
@@ -2,15 +2,54 @@ import gleam/result
import gleam/list
import gleam/result.{Option}
-/// An Erlang map. See [the Erlang map module](https://erlang.org/doc/man/maps.html) for details
+/// A dictionary of keys and values.
+///
+/// Any type can be used for the keys and values of a map, but all the keys
+/// must be of the same type and all the values must be of the same type.
+///
+/// Each key can only be present in a map once.
+///
+/// Maps are not ordered in any way, and any unintentional ordering is not to
+/// be relied upon in your code.
+///
+/// See [the Erlang map module](https://erlang.org/doc/man/maps.html) for more
+/// information.
+///
pub external type Map(key, value);
+/// Determine the number of key-value pairs in the map.
+/// This function runs in constant time and does not need to iterate the map.
+///
+/// ## Examples
+///
+/// ```
+/// new() |> size() == 0
+/// new() |> insert("key", "value") |> size() == 1
+/// ```
+///
pub external fn size(Map(k, v)) -> Int
= "maps" "size"
+/// Convert the map to a list of 2-element tuples `tuple(key, value)`, one for
+/// each key-value pair in the map.
+///
+/// The tuples in the list have no specific order.
+///
+/// ## Examples
+///
+/// ```
+/// new() |> to_list() == []
+/// new() |> insert("key", 0) |> to_list() == [tuple("key", 0)]
+/// ```
+///
pub external fn to_list(Map(key, value)) -> List(tuple(key, value))
= "maps" "to_list"
+/// Convert a list of 2-element tuples `tuple(key, value)` to a map.
+///
+/// If two tuples have the same key the last one in the list will be the one
+/// that is present in the map.
+///
pub external fn from_list(List(tuple(key, value))) -> Map(key, value)
= "maps" "from_list"
diff --git a/src/gleam/order.gleam b/src/gleam/order.gleam
index 4b12af7..ce58db0 100644
--- a/src/gleam/order.gleam
+++ b/src/gleam/order.gleam
@@ -1,6 +1,5 @@
/// Represents the result of a single comparison to determine the precise
/// ordering of two values.
-
pub type Order {
Lt
Eq
diff --git a/src/gleam/pair.gleam b/src/gleam/pair.gleam
index 5883328..54fea2f 100644
--- a/src/gleam/pair.gleam
+++ b/src/gleam/pair.gleam
@@ -1,5 +1,3 @@
-// A set of utility functions for working with 2-tuples, or pairs.
-
/// Returns the first element in a pair.
///
/// ## Examples
diff --git a/src/gleam/result.gleam b/src/gleam/result.gleam
index e4ea275..2558e57 100644
--- a/src/gleam/result.gleam
+++ b/src/gleam/result.gleam
@@ -1,12 +1,21 @@
/// Result represents the result of something that may succeed or fail.
/// `Ok` means it was successful, `Error` means it failed.
-
pub type Result(success, error) =
Result(success, error)
+/// Nil is a type used to represent the absence of something, similar to null
+/// or undefined in other languages.
+///
+/// Unlike some other languages values cannot be implicitly nil, value that may
+/// be absent is typically represented using `Result(TheType, Nil)`. This is
+/// such a common type that offer the `Option(TheType)` alias.
pub type Nil =
Nil
+/// A value that is either there or not there.
+pub type Option(value) =
+ Result(value, Nil)
+
/// Returns whether the value is Ok
///
pub fn is_ok(result: Result(a, e)) -> Bool {
@@ -81,10 +90,14 @@ pub fn unwrap(result: Result(a, e), or default: a) -> a {
}
}
-/// A value that is either there or not there
-pub type Option(value) =
- Result(value, Nil)
-
+/// Another way of writing `Error(Nil)`.
+///
+/// ## Examples
+///
+/// ```
+/// none() == Error(Nil)
+/// ```
+///
pub fn none() -> Option(a) {
Error(Nil)
}
diff --git a/test/gleam/map_test.gleam b/test/gleam/map_test.gleam
index 27e47f6..c19cfcd 100644
--- a/test/gleam/map_test.gleam
+++ b/test/gleam/map_test.gleam
@@ -10,6 +10,13 @@ pub fn from_list_test() {
|> map.from_list
|> map.size
|> should.equal(_, 2)
+
+ [
+ tuple(1, 0),
+ tuple(1, 1),
+ ]
+ |> map.from_list
+ |> should.equal(map.from_list([tuple(1, 1)]))
}
pub fn has_key_test() {