Packages
gleam_stdlib
0.16.0
1.0.3
1.0.2
1.0.1
1.0.0
0.71.0
0.70.0
0.69.0
0.68.1
0.68.0
0.67.1
0.67.0
0.65.0
0.64.0
0.63.2
0.63.1
0.63.0
0.62.1
0.62.0
0.61.0
0.60.0
0.59.0
0.58.0
0.57.0
0.56.0
0.55.0
0.54.0
0.53.0
0.52.0
0.51.0
0.50.0
0.49.0
0.48.0
0.47.0
0.46.0
0.45.0
0.44.0
0.43.0
0.42.0
0.41.0
0.40.0
0.39.0
0.38.0
0.37.0
0.36.0
0.35.1
0.35.0
0.34.0
0.33.1
0.33.0
0.32.1
0.32.0
0.31.0
0.30.2
0.30.1
0.30.0
0.29.2
0.29.1
0.29.0
0.28.2
0.28.1
0.28.0
0.27.0
0.26.1
0.26.0
0.25.0
0.24.0
0.23.0
0.22.3
0.22.2
0.22.1
0.22.0
0.21.0
0.20.0
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.18.0-rc1
0.17.1
0.17.0
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.4.0-rc1
0.3.1
0.3.0
0.2.0
retired
A standard library for the Gleam programming language
Current section
Files
Jump to
Current section
Files
gen/test/gleam@list_test.erl
-module(gleam@list_test).
-compile(no_auto_import).
-export([length_test/0, reverse_test/0, is_empty_test/0, contains_test/0, head_test/0, tail_test/0, filter_test/0, filter_map_test/0, map_test/0, map_fold_test/0, try_map_test/0, drop_test/0, take_test/0, new_test/0, append_test/0, flatten_test/0, flat_map_test/0, fold_test/0, fold_right_test/0, index_fold_test/0, fold_until_test/0, try_fold_test/0, find_map_test/0, find_test/0, all_test/0, any_test/0, zip_test/0, strict_zip_test/0, unzip_test/0, intersperse_test/0, at_test/0, unique_test/0, sort_test/0, index_map_test/0, range_test/0, repeat_test/0, split_test/0, split_while_test/0, key_find_test/0, pop_test/0, pop_map_test/0, key_pop_test/0, key_set_test/0, partition_test/0, permutations_test/0, window_test/0, window_by_2_test/0, drop_while_test/0, take_while_test/0, chunk_test/0, sized_chunk_test/0, reduce_test/0, scan_test/0, last_test/0, combinations_test/0, combination_pairs_test/0, interleave_test/0, transpose_test/0]).
-spec length_test() -> gleam@should:expectation().
length_test() ->
gleam@should:equal(gleam@list:length([]), 0),
gleam@should:equal(gleam@list:length([1]), 1),
gleam@should:equal(gleam@list:length([1, 1]), 2),
gleam@should:equal(gleam@list:length([1, 1, 1]), 3).
-spec reverse_test() -> gleam@should:expectation().
reverse_test() ->
gleam@should:equal(gleam@list:reverse([]), []),
gleam@should:equal(gleam@list:reverse([1, 2, 3, 4, 5]), [5, 4, 3, 2, 1]).
-spec is_empty_test() -> gleam@should:expectation().
is_empty_test() ->
gleam@should:be_true(gleam@list:is_empty([])),
gleam@should:be_false(gleam@list:is_empty([1])).
-spec contains_test() -> gleam@should:expectation().
contains_test() ->
gleam@should:be_true(gleam@list:contains([0, 4, 5, 1], 1)),
gleam@should:be_false(gleam@list:contains([0, 4, 5, 7], 1)),
gleam@should:be_false(gleam@list:contains([], 1)).
-spec head_test() -> gleam@should:expectation().
head_test() ->
gleam@should:equal(gleam@list:head([0, 4, 5, 7]), {ok, 0}),
gleam@should:equal(gleam@list:head([]), {error, nil}).
-spec tail_test() -> gleam@should:expectation().
tail_test() ->
gleam@should:equal(gleam@list:tail([0, 4, 5, 7]), {ok, [4, 5, 7]}),
gleam@should:equal(gleam@list:tail([0]), {ok, []}),
gleam@should:equal(gleam@list:tail([]), {error, nil}).
-spec filter_test() -> gleam@should:expectation().
filter_test() ->
gleam@should:equal(gleam@list:filter([], fun(_) -> true end), []),
gleam@should:equal(
gleam@list:filter([0, 4, 5, 7, 3], fun(_) -> true end),
[0, 4, 5, 7, 3]
),
gleam@should:equal(
gleam@list:filter([0, 4, 5, 7, 3], fun(X) -> X > 4 end),
[5, 7]
),
gleam@should:equal(
gleam@list:filter([0, 4, 5, 7, 3], fun(X@1) -> X@1 < 4 end),
[0, 3]
).
-spec filter_map_test() -> gleam@should:expectation().
filter_map_test() ->
gleam@should:equal(
gleam@list:filter_map([2, 4, 6, 1], fun(X) -> {ok, X + 1} end),
[3, 5, 7, 2]
),
gleam@should:equal(
gleam@list:filter_map([2, 4, 6, 1], fun(A) -> {error, A} end),
[]
).
-spec map_test() -> gleam@should:expectation().
map_test() ->
gleam@should:equal(gleam@list:map([], fun(X) -> X * 2 end), []),
gleam@should:equal(
gleam@list:map([0, 4, 5, 7, 3], fun(X@1) -> X@1 * 2 end),
[0, 8, 10, 14, 6]
).
-spec map_fold_test() -> gleam@should:expectation().
map_fold_test() ->
gleam@should:equal(
gleam@list:map_fold(
[1, 2, 3, 4],
0,
fun(I, Acc) -> {I * 2, Acc + I} end
),
{[2, 4, 6, 8], 10}
).
-spec try_map_test() -> gleam@should:expectation().
try_map_test() ->
Fun = fun(X) -> case ((X =:= 6) orelse (X =:= 5)) orelse (X =:= 4) of
true ->
{ok, X * 2};
false ->
{error, X}
end end,
gleam@should:equal(
gleam@list:try_map([5, 6, 5, 6], Fun),
{ok, [10, 12, 10, 12]}
),
gleam@should:equal(gleam@list:try_map([4, 6, 5, 7, 3], Fun), {error, 7}).
-spec drop_test() -> gleam@should:expectation().
drop_test() ->
gleam@should:equal(gleam@list:drop([], 5), []),
gleam@should:equal(gleam@list:drop([1, 2, 3, 4, 5, 6, 7, 8], 5), [6, 7, 8]).
-spec take_test() -> gleam@should:expectation().
take_test() ->
gleam@should:equal(gleam@list:take([], 5), []),
gleam@should:equal(
gleam@list:take([1, 2, 3, 4, 5, 6, 7, 8], 5),
[1, 2, 3, 4, 5]
).
-spec new_test() -> gleam@should:expectation().
new_test() ->
gleam@should:equal(gleam@list:new(), []).
-spec append_test() -> gleam@should:expectation().
append_test() ->
gleam@should:equal(gleam@list:append([1], [2, 3]), [1, 2, 3]).
-spec flatten_test() -> gleam@should:expectation().
flatten_test() ->
gleam@should:equal(gleam@list:flatten([]), []),
gleam@should:equal(gleam@list:flatten([[]]), []),
gleam@should:equal(gleam@list:flatten([[], [], []]), []),
gleam@should:equal(gleam@list:flatten([[1, 2], [], [3, 4]]), [1, 2, 3, 4]).
-spec flat_map_test() -> gleam@should:expectation().
flat_map_test() ->
gleam@should:equal(
gleam@list:flat_map([1, 10, 20], fun(X) -> [X, X + 1] end),
[1, 2, 10, 11, 20, 21]
).
-spec fold_test() -> gleam@should:expectation().
fold_test() ->
gleam@should:equal(
gleam@list:fold([1, 2, 3], [], fun(X, Acc) -> [X | Acc] end),
[3, 2, 1]
).
-spec fold_right_test() -> gleam@should:expectation().
fold_right_test() ->
gleam@should:equal(
gleam@list:fold_right([1, 2, 3], [], fun(X, Acc) -> [X | Acc] end),
[1, 2, 3]
).
-spec index_fold_test() -> gleam@should:expectation().
index_fold_test() ->
gleam@should:equal(
gleam@list:index_fold(
[<<"a"/utf8>>, <<"b"/utf8>>, <<"c"/utf8>>],
[],
fun(Ix, I, Acc) -> [{Ix, I} | Acc] end
),
[{2, <<"c"/utf8>>}, {1, <<"b"/utf8>>}, {0, <<"a"/utf8>>}]
).
-spec fold_until_test() -> gleam@should:expectation().
fold_until_test() ->
gleam@should:equal(
gleam@list:fold_until([1, 2, 3, 4], 0, fun(N, Acc) -> case N < 4 of
true ->
{continue, Acc + N};
false ->
{stop, Acc}
end end),
6
).
-spec try_fold_test() -> gleam@should:expectation().
try_fold_test() ->
gleam@should:equal(
gleam@list:try_fold([1, 2, 3], 0, fun(I, Acc) -> case I < 4 of
true ->
{ok, Acc + I};
false ->
{error, nil}
end end),
{ok, 6}
),
gleam@should:equal(
gleam@list:try_fold([1, 2, 3], 0, fun(I@1, Acc@1) -> case I@1 < 3 of
true ->
{ok, Acc@1 + I@1};
false ->
{error, nil}
end end),
{error, nil}
).
-spec find_map_test() -> gleam@should:expectation().
find_map_test() ->
F = fun(X) -> case X of
2 ->
{ok, 4};
_ ->
{error, nil}
end end,
gleam@should:equal(gleam@list:find_map([1, 2, 3], F), {ok, 4}),
gleam@should:equal(gleam@list:find_map([1, 3, 2], F), {ok, 4}),
gleam@should:equal(gleam@list:find_map([1, 3], F), {error, nil}).
-spec find_test() -> gleam@should:expectation().
find_test() ->
Is_two = fun(X) -> X =:= 2 end,
gleam@should:equal(gleam@list:find([1, 2, 3], Is_two), {ok, 2}),
gleam@should:equal(gleam@list:find([1, 3, 2], Is_two), {ok, 2}),
gleam@should:equal(gleam@list:find([1, 3], Is_two), {error, nil}).
-spec all_test() -> gleam@should:expectation().
all_test() ->
gleam@should:equal(
gleam@list:all([1, 2, 3, 4, 5], fun(X) -> X > 0 end),
true
),
gleam@should:equal(
gleam@list:all([1, 2, 3, 4, 5], fun(X@1) -> X@1 < 0 end),
false
),
gleam@should:equal(gleam@list:all([], fun(_) -> false end), true).
-spec any_test() -> gleam@should:expectation().
any_test() ->
gleam@should:equal(
gleam@list:any([1, 2, 3, 4, 5], fun(X) -> X =:= 2 end),
true
),
gleam@should:equal(
gleam@list:any([1, 2, 3, 4, 5], fun(X@1) -> X@1 < 0 end),
false
),
gleam@should:equal(gleam@list:any([], fun(_) -> false end), false).
-spec zip_test() -> gleam@should:expectation().
zip_test() ->
gleam@should:equal(gleam@list:zip([], [1, 2, 3]), []),
gleam@should:equal(gleam@list:zip([1, 2], []), []),
gleam@should:equal(
gleam@list:zip([1, 2, 3], [4, 5, 6]),
[{1, 4}, {2, 5}, {3, 6}]
),
gleam@should:equal(gleam@list:zip([5, 6], [1, 2, 3]), [{5, 1}, {6, 2}]),
gleam@should:equal(gleam@list:zip([5, 6, 7], [1, 2]), [{5, 1}, {6, 2}]).
-spec strict_zip_test() -> gleam@should:expectation().
strict_zip_test() ->
gleam@should:equal(
gleam@list:strict_zip([], [1, 2, 3]),
{error, length_mismatch}
),
gleam@should:equal(
gleam@list:strict_zip([1, 2], []),
{error, length_mismatch}
),
gleam@should:equal(
gleam@list:strict_zip([1, 2, 3], [4, 5, 6]),
{ok, [{1, 4}, {2, 5}, {3, 6}]}
),
gleam@should:equal(
gleam@list:strict_zip([5, 6], [1, 2, 3]),
{error, length_mismatch}
),
gleam@should:equal(
gleam@list:strict_zip([5, 6, 7], [1, 2]),
{error, length_mismatch}
).
-spec unzip_test() -> gleam@should:expectation().
unzip_test() ->
gleam@should:equal(gleam@list:unzip([{1, 2}, {3, 4}]), {[1, 3], [2, 4]}),
gleam@should:equal(gleam@list:unzip([]), {[], []}).
-spec intersperse_test() -> gleam@should:expectation().
intersperse_test() ->
gleam@should:equal(gleam@list:intersperse([1, 2, 3], 4), [1, 4, 2, 4, 3]),
gleam@should:equal(gleam@list:intersperse([], 2), []).
-spec at_test() -> gleam@should:expectation().
at_test() ->
gleam@should:equal(gleam@list:at([1, 2, 3], 2), {ok, 3}),
gleam@should:equal(gleam@list:at([1, 2, 3], 5), {error, nil}),
gleam@should:equal(gleam@list:at([], 0), {error, nil}),
gleam@should:equal(gleam@list:at([1, 2, 3, 4, 5, 6], -1), {error, nil}).
-spec unique_test() -> gleam@should:expectation().
unique_test() ->
gleam@should:equal(
gleam@list:unique([1, 1, 2, 3, 4, 4, 4, 5, 6]),
[1, 2, 3, 4, 5, 6]
),
gleam@should:equal(
gleam@list:unique([7, 1, 45, 6, 2, 47, 2, 7, 5]),
[7, 1, 45, 6, 2, 47, 5]
),
gleam@should:equal(gleam@list:unique([3, 4, 5]), [3, 4, 5]),
gleam@should:equal(gleam@list:unique([]), []).
-spec sort_test() -> gleam@should:expectation().
sort_test() ->
gleam@should:equal(
gleam@list:sort([4, 3, 6, 5, 4], fun gleam@int:compare/2),
[3, 4, 4, 5, 6]
),
gleam@should:equal(
gleam@list:sort([4, 3, 6, 5, 4, 1], fun gleam@int:compare/2),
[1, 3, 4, 4, 5, 6]
),
gleam@should:equal(
gleam@list:sort([4.1, 3.1, 6.1, 5.1, 4.1], fun gleam@float:compare/2),
[3.1, 4.1, 4.1, 5.1, 6.1]
),
gleam@should:equal(gleam@list:sort([], fun gleam@int:compare/2), []).
-spec index_map_test() -> gleam@should:expectation().
index_map_test() ->
gleam@should:equal(
gleam@list:index_map([3, 4, 5], fun(I, X) -> {I, X} end),
[{0, 3}, {1, 4}, {2, 5}]
),
F = fun(I@1, X@1) -> gleam@string:append(X@1, gleam@int:to_string(I@1)) end,
gleam@should:equal(
gleam@list:index_map([<<"a"/utf8>>, <<"b"/utf8>>, <<"c"/utf8>>], F),
[<<"a0"/utf8>>, <<"b1"/utf8>>, <<"c2"/utf8>>]
).
-spec range_test() -> gleam@should:expectation().
range_test() ->
gleam@should:equal(gleam@list:range(0, 0), []),
gleam@should:equal(gleam@list:range(1, 1), []),
gleam@should:equal(gleam@list:range(-1, -1), []),
gleam@should:equal(gleam@list:range(0, 1), [0]),
gleam@should:equal(gleam@list:range(0, 5), [0, 1, 2, 3, 4]),
gleam@should:equal(gleam@list:range(1, -5), [1, 0, -1, -2, -3, -4]).
-spec repeat_test() -> gleam@should:expectation().
repeat_test() ->
gleam@should:equal(gleam@list:repeat(1, -10), []),
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"/utf8>>, 5),
[<<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>, <<"x"/utf8>>]
).
-spec split_test() -> gleam@should:expectation().
split_test() ->
gleam@should:equal(gleam@list:split([], 0), {[], []}),
gleam@should:equal(
gleam@list:split([0, 1, 2, 3, 4], 0),
{[], [0, 1, 2, 3, 4]}
),
gleam@should:equal(
gleam@list:split([0, 1, 2, 3, 4], -2),
{[], [0, 1, 2, 3, 4]}
),
gleam@should:equal(
gleam@list:split([0, 1, 2, 3, 4], 1),
{[0], [1, 2, 3, 4]}
),
gleam@should:equal(
gleam@list:split([0, 1, 2, 3, 4], 3),
{[0, 1, 2], [3, 4]}
),
gleam@should:equal(
gleam@list:split([0, 1, 2, 3, 4], 9),
{[0, 1, 2, 3, 4], []}
).
-spec split_while_test() -> gleam@should:expectation().
split_while_test() ->
gleam@should:equal(
gleam@list:split_while([], fun(X) -> X =< 5 end),
{[], []}
),
gleam@should:equal(
gleam@list:split_while([1, 2, 3, 4, 5], fun(X@1) -> X@1 =< 5 end),
{[1, 2, 3, 4, 5], []}
),
gleam@should:equal(
gleam@list:split_while([1, 2, 3, 4, 5], fun(X@2) -> X@2 =:= 2 end),
{[], [1, 2, 3, 4, 5]}
),
gleam@should:equal(
gleam@list:split_while([1, 2, 3, 4, 5], fun(X@3) -> X@3 =< 3 end),
{[1, 2, 3], [4, 5]}
),
gleam@should:equal(
gleam@list:split_while([1, 2, 3, 4, 5], fun(X@4) -> X@4 =< -3 end),
{[], [1, 2, 3, 4, 5]}
).
-spec key_find_test() -> gleam@should:expectation().
key_find_test() ->
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}).
-spec pop_test() -> gleam@should:expectation().
pop_test() ->
gleam@should:equal(
gleam@list:pop([1, 2, 3], fun(X) -> X > 2 end),
{ok, {3, [1, 2]}}
),
gleam@should:equal(
gleam@list:pop([1, 2, 3], fun(X@1) -> X@1 > 4 end),
{error, nil}
),
gleam@should:equal(gleam@list:pop([], fun(_) -> true end), {error, nil}).
-spec pop_map_test() -> gleam@should:expectation().
pop_map_test() ->
gleam@should:equal(
gleam@list:pop_map(
[<<"foo"/utf8>>, <<"2"/utf8>>, <<"3"/utf8>>],
fun gleam@int:parse/1
),
{ok, {2, [<<"foo"/utf8>>, <<"3"/utf8>>]}}
),
gleam@should:equal(
gleam@list:pop_map(
[<<"foo"/utf8>>, <<"bar"/utf8>>],
fun gleam@int:parse/1
),
{error, nil}
),
gleam@should:equal(
gleam@list:pop_map([], fun gleam@int:parse/1),
{error, nil}
).
-spec key_pop_test() -> gleam@should:expectation().
key_pop_test() ->
gleam@should:equal(
gleam@list:key_pop([{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}], <<"a"/utf8>>),
{ok, {0, [{<<"b"/utf8>>, 1}]}}
),
gleam@should:equal(
gleam@list:key_pop([{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}], <<"b"/utf8>>),
{ok, {1, [{<<"a"/utf8>>, 0}]}}
),
gleam@should:equal(
gleam@list:key_pop([{<<"a"/utf8>>, 0}, {<<"b"/utf8>>, 1}], <<"c"/utf8>>),
{error, nil}
).
-spec key_set_test() -> gleam@should:expectation().
key_set_test() ->
gleam@should:equal(
gleam@list:key_set([{5, 0}, {4, 1}], 4, 100),
[{5, 0}, {4, 100}]
),
gleam@should:equal(
gleam@list:key_set([{5, 0}, {4, 1}], 1, 100),
[{5, 0}, {4, 1}, {1, 100}]
).
-spec partition_test() -> gleam@should:expectation().
partition_test() ->
gleam@should:equal(
gleam@list:partition([1, 2, 3, 4, 5, 6, 7], fun gleam@int:is_odd/1),
{[1, 3, 5, 7], [2, 4, 6]}
).
-spec permutations_test() -> gleam@should:expectation().
permutations_test() ->
gleam@should:equal(gleam@list:permutations([1, 2]), [[1, 2], [2, 1]]),
Expected = [[1, 2, 3],
[1, 3, 2],
[2, 1, 3],
[2, 3, 1],
[3, 1, 2],
[3, 2, 1]],
gleam@should:equal(gleam@list:permutations([1, 2, 3]), Expected),
gleam@should:equal(
gleam@list:permutations([<<"a"/utf8>>, <<"b"/utf8>>]),
[[<<"a"/utf8>>, <<"b"/utf8>>], [<<"b"/utf8>>, <<"a"/utf8>>]]
).
-spec window_test() -> gleam@should:expectation().
window_test() ->
gleam@should:equal(gleam@list:window([1, 2, 3], 2), [[1, 2], [2, 3]]),
gleam@should:equal(gleam@list:window([1, 2, 3], 3), [[1, 2, 3]]),
gleam@should:equal(gleam@list:window([1, 2, 3], 4), []),
gleam@should:equal(
gleam@list:window([1, 2, 3, 4, 5], 3),
[[1, 2, 3], [2, 3, 4], [3, 4, 5]]
).
-spec window_by_2_test() -> gleam@should:expectation().
window_by_2_test() ->
gleam@should:equal(
gleam@list:window_by_2([1, 2, 3, 4]),
[{1, 2}, {2, 3}, {3, 4}]
),
gleam@should:equal(gleam@list:window_by_2([1]), []).
-spec drop_while_test() -> gleam@should:expectation().
drop_while_test() ->
gleam@should:equal(
gleam@list:drop_while([1, 2, 3, 4], fun(X) -> X < 3 end),
[3, 4]
).
-spec take_while_test() -> gleam@should:expectation().
take_while_test() ->
gleam@should:equal(
gleam@list:take_while([1, 2, 3, 2, 4], fun(X) -> X < 3 end),
[1, 2]
).
-spec chunk_test() -> gleam@should:expectation().
chunk_test() ->
gleam@should:equal(
gleam@list:chunk([1, 2, 2, 3, 4, 4, 6, 7, 7], fun(N) -> N rem 2 end),
[[1], [2, 2], [3], [4, 4, 6], [7, 7]]
).
-spec sized_chunk_test() -> gleam@should:expectation().
sized_chunk_test() ->
gleam@should:equal(
gleam@list:sized_chunk([1, 2, 3, 4, 5, 6], 2),
[[1, 2], [3, 4], [5, 6]]
),
gleam@should:equal(
gleam@list:sized_chunk([1, 2, 3, 4, 5, 6, 7, 8], 3),
[[1, 2, 3], [4, 5, 6], [7, 8]]
).
-spec reduce_test() -> gleam@should:expectation().
reduce_test() ->
gleam@should:equal(
gleam@list:reduce([], fun(X, Y) -> X + Y end),
{error, nil}
),
gleam@should:equal(
gleam@list:reduce([1, 2, 3, 4, 5], fun(X@1, Y@1) -> X@1 + Y@1 end),
{ok, 15}
).
-spec scan_test() -> gleam@should:expectation().
scan_test() ->
gleam@should:equal(gleam@list:scan([], 0, fun(I, Acc) -> I + Acc end), []),
gleam@should:equal(
gleam@list:scan(
[1, 2, 3, 4],
0,
fun(I@1, Acc@1) -> (2 * I@1) + Acc@1 end
),
[2, 6, 12, 20]
),
gleam@should:equal(
gleam@list:scan(
[1, 2, 3, 4],
<<""/utf8>>,
fun(I@2, Acc@2) ->
gleam@string:append(Acc@2, case gleam@int:is_even(I@2) of
true ->
<<"Even"/utf8>>;
false ->
<<"Odd"/utf8>>
end)
end
),
[<<"Odd"/utf8>>,
<<"OddEven"/utf8>>,
<<"OddEvenOdd"/utf8>>,
<<"OddEvenOddEven"/utf8>>]
).
-spec last_test() -> gleam@should:expectation().
last_test() ->
gleam@should:equal(gleam@list:last([]), {error, nil}),
gleam@should:equal(gleam@list:last([1, 2, 3, 4, 5]), {ok, 5}).
-spec combinations_test() -> gleam@should:expectation().
combinations_test() ->
gleam@should:equal(gleam@list:combinations([1, 2, 3], 0), [[]]),
gleam@should:equal(gleam@list:combinations([1, 2, 3], 1), [[1], [2], [3]]),
gleam@should:equal(
gleam@list:combinations([1, 2, 3], 2),
[[1, 2], [1, 3], [2, 3]]
),
gleam@should:equal(gleam@list:combinations([1, 2, 3], 3), [[1, 2, 3]]),
gleam@should:equal(gleam@list:combinations([1, 2, 3], 4), []),
gleam@should:equal(
gleam@list:combinations([1, 2, 3, 4], 3),
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
).
-spec combination_pairs_test() -> gleam@should:expectation().
combination_pairs_test() ->
gleam@should:equal(gleam@list:combination_pairs([1]), []),
gleam@should:equal(gleam@list:combination_pairs([1, 2]), [{1, 2}]),
gleam@should:equal(
gleam@list:combination_pairs([1, 2, 3]),
[{1, 2}, {1, 3}, {2, 3}]
),
gleam@should:equal(
gleam@list:combination_pairs([1, 2, 3, 4]),
[{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}]
).
-spec interleave_test() -> gleam@should:expectation().
interleave_test() ->
gleam@should:equal(
gleam@list:interleave([[1, 2], [101, 102]]),
[1, 101, 2, 102]
),
gleam@should:equal(
gleam@list:interleave([[1, 2], [101, 102], [201, 202]]),
[1, 101, 201, 2, 102, 202]
),
gleam@should:equal(
gleam@list:interleave([[1, 2, 3], [101, 102]]),
[1, 101, 2, 102, 3]
),
gleam@should:equal(
gleam@list:interleave([[1, 2], [101, 102, 103]]),
[1, 101, 2, 102, 103]
).
-spec transpose_test() -> gleam@should:expectation().
transpose_test() ->
gleam@should:equal(
gleam@list:transpose([[1, 2, 3], [101, 102, 103]]),
[[1, 101], [2, 102], [3, 103]]
),
gleam@should:equal(
gleam@list:transpose([[1, 2, 3], [101, 102, 103], [201, 202, 203]]),
[[1, 101, 201], [2, 102, 202], [3, 103, 203]]
),
gleam@should:equal(
gleam@list:transpose([[1, 2], [101, 102, 103]]),
[[1, 101], [2, 102], [103]]
),
gleam@should:equal(
gleam@list:transpose([[1, 2, 3], [101, 102], [201, 202, 203]]),
[[1, 101, 201], [2, 102, 202], [3, 203]]
).