Current section
Files
Jump to
Current section
Files
src/gleam@list.erl
-module(gleam@list).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([length/1, reverse/1, is_empty/1, contains/2, first/1, rest/1, filter/2, filter_map/2, map/2, map2/3, index_map/2, try_map/2, drop/2, take/2, new/0, append/2, prepend/2, concat/1, flatten/1, flat_map/2, fold/3, group/2, map_fold/3, fold_right/3, index_fold/3, try_fold/3, fold_until/3, find/2, find_map/2, all/2, any/2, zip/2, strict_zip/2, unzip/1, intersperse/2, at/2, unique/1, sort/2, range/2, repeat/2, split/2, split_while/2, key_find/2, key_filter/2, pop/2, pop_map/2, key_pop/2, key_set/3, each/2, try_each/2, partition/2, permutations/1, window/2, window_by_2/1, drop_while/2, take_while/2, chunk/2, sized_chunk/2, reduce/2, scan/3, last/1, combinations/2, combination_pairs/1, transpose/1, interleave/1, shuffle/1]).
-export_type([continue_or_stop/1]).
-type continue_or_stop(XR) :: {continue, XR} | {stop, XR}.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 61).
-spec count_length(list(any()), integer()) -> integer().
count_length(List, Count) ->
case List of
[_ | List@1] ->
count_length(List@1, Count + 1);
_ ->
Count
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 57).
-spec length(list(any())) -> integer().
length(List) ->
erlang:length(List).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 99).
-spec do_reverse(list(APU), list(APU)) -> list(APU).
do_reverse(Remaining, Accumulator) ->
case Remaining of
[] ->
Accumulator;
[Item | Rest] ->
do_reverse(Rest, [Item | Accumulator])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 95).
-spec reverse(list(XW)) -> list(XW).
reverse(Xs) ->
lists:reverse(Xs).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 127).
-spec is_empty(list(any())) -> boolean().
is_empty(List) ->
List =:= [].
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 163).
-spec contains(list(YE), YE) -> boolean().
contains(List, Elem) ->
case List of
[] ->
false;
[First | _] when First =:= Elem ->
true;
[_ | Rest] ->
contains(Rest, Elem)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 190).
-spec first(list(YG)) -> {ok, YG} | {error, nil}.
first(List) ->
case List of
[] ->
{error, nil};
[X | _] ->
{ok, X}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 219).
-spec rest(list(YK)) -> {ok, list(YK)} | {error, nil}.
rest(List) ->
case List of
[] ->
{error, nil};
[_ | Xs] ->
{ok, Xs}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 226).
-spec update_group(fun((YP) -> YQ)) -> fun((gleam@dict:dict(YQ, list(YP)), YP) -> gleam@dict:dict(YQ, list(YP))).
update_group(F) ->
fun(Groups, Elem) -> case gleam@dict:get(Groups, F(Elem)) of
{ok, Existing} ->
gleam@dict:insert(Groups, F(Elem), [Elem | Existing]);
{error, _} ->
gleam@dict:insert(Groups, F(Elem), [Elem])
end end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 272).
-spec do_filter(list(AAD), fun((AAD) -> boolean()), list(AAD)) -> list(AAD).
do_filter(List, Fun, Acc) ->
case List of
[] ->
lists:reverse(Acc);
[X | Xs] ->
New_acc = case Fun(X) of
true ->
[X | Acc];
false ->
Acc
end,
do_filter(Xs, Fun, New_acc)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 300).
-spec filter(list(AAH), fun((AAH) -> boolean())) -> list(AAH).
filter(List, Predicate) ->
do_filter(List, Predicate, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 304).
-spec do_filter_map(
list(AAK),
fun((AAK) -> {ok, AAM} | {error, any()}),
list(AAM)
) -> list(AAM).
do_filter_map(List, Fun, Acc) ->
case List of
[] ->
lists:reverse(Acc);
[X | Xs] ->
New_acc = case Fun(X) of
{ok, X@1} ->
[X@1 | Acc];
{error, _} ->
Acc
end,
do_filter_map(Xs, Fun, New_acc)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 336).
-spec filter_map(list(AAS), fun((AAS) -> {ok, AAU} | {error, any()})) -> list(AAU).
filter_map(List, Fun) ->
do_filter_map(List, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 340).
-spec do_map(list(AAZ), fun((AAZ) -> ABB), list(ABB)) -> list(ABB).
do_map(List, Fun, Acc) ->
case List of
[] ->
lists:reverse(Acc);
[X | Xs] ->
do_map(Xs, Fun, [Fun(X) | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 357).
-spec map(list(ABE), fun((ABE) -> ABG)) -> list(ABG).
map(List, Fun) ->
do_map(List, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 381).
-spec do_map2(list(ABO), list(ABQ), fun((ABO, ABQ) -> ABS), list(ABS)) -> list(ABS).
do_map2(List1, List2, Fun, Acc) ->
case {List1, List2} of
{[], _} ->
lists:reverse(Acc);
{_, []} ->
lists:reverse(Acc);
{[A | As_], [B | Bs]} ->
do_map2(As_, Bs, Fun, [Fun(A, B) | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 377).
-spec map2(list(ABI), list(ABK), fun((ABI, ABK) -> ABM)) -> list(ABM).
map2(List1, List2, Fun) ->
do_map2(List1, List2, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 419).
-spec do_index_map(
list(ACA),
fun((ACA, integer()) -> ACC),
integer(),
list(ACC)
) -> list(ACC).
do_index_map(List, Fun, Index, Acc) ->
case List of
[] ->
lists:reverse(Acc);
[X | Xs] ->
Acc@1 = [Fun(X, Index) | Acc],
do_index_map(Xs, Fun, Index + 1, Acc@1)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 447).
-spec index_map(list(ACF), fun((ACF, integer()) -> ACH)) -> list(ACH).
index_map(List, Fun) ->
do_index_map(List, Fun, 0, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 451).
-spec do_try_map(list(ACJ), fun((ACJ) -> {ok, ACL} | {error, ACM}), list(ACL)) -> {ok,
list(ACL)} |
{error, ACM}.
do_try_map(List, Fun, Acc) ->
case List of
[] ->
{ok, lists:reverse(Acc)};
[X | Xs] ->
case Fun(X) of
{ok, Y} ->
do_try_map(Xs, Fun, [Y | Acc]);
{error, Error} ->
{error, Error}
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 498).
-spec try_map(list(ACT), fun((ACT) -> {ok, ACV} | {error, ACW})) -> {ok,
list(ACV)} |
{error, ACW}.
try_map(List, Fun) ->
do_try_map(List, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 525).
-spec drop(list(ADC), integer()) -> list(ADC).
drop(List, N) ->
case N =< 0 of
true ->
List;
false ->
case List of
[] ->
[];
[_ | Xs] ->
drop(Xs, N - 1)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 536).
-spec do_take(list(ADF), integer(), list(ADF)) -> list(ADF).
do_take(List, N, Acc) ->
case N =< 0 of
true ->
lists:reverse(Acc);
false ->
case List of
[] ->
lists:reverse(Acc);
[X | Xs] ->
do_take(Xs, N - 1, [X | Acc])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 567).
-spec take(list(ADJ), integer()) -> list(ADJ).
take(List, N) ->
do_take(List, N, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 580).
-spec new() -> list(any()).
new() ->
[].
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 601).
-spec do_append(list(ADS), list(ADS)) -> list(ADS).
do_append(First, Second) ->
case First of
[] ->
Second;
[Item | Rest] ->
do_append(Rest, [Item | Second])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 597).
-spec append(list(ADO), list(ADO)) -> list(ADO).
append(First, Second) ->
lists:append(First, Second).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 621).
-spec prepend(list(ADW), ADW) -> list(ADW).
prepend(List, Item) ->
[Item | List].
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 626).
-spec reverse_and_prepend(list(ADZ), list(ADZ)) -> list(ADZ).
reverse_and_prepend(Prefix, Suffix) ->
case Prefix of
[] ->
Suffix;
[First | Rest] ->
reverse_and_prepend(Rest, [First | Suffix])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 633).
-spec do_concat(list(list(AED)), list(AED)) -> list(AED).
do_concat(Lists, Acc) ->
case Lists of
[] ->
lists:reverse(Acc);
[List | Further_lists] ->
do_concat(Further_lists, reverse_and_prepend(List, Acc))
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 652).
-spec concat(list(list(AEI))) -> list(AEI).
concat(Lists) ->
do_concat(Lists, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 668).
-spec flatten(list(list(AEM))) -> list(AEM).
flatten(Lists) ->
do_concat(Lists, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 681).
-spec flat_map(list(AEQ), fun((AEQ) -> list(AES))) -> list(AES).
flat_map(List, Fun) ->
_pipe = map(List, Fun),
concat(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 694).
-spec fold(list(AEV), AEX, fun((AEX, AEV) -> AEX)) -> AEX.
fold(List, Initial, Fun) ->
case List of
[] ->
Initial;
[X | Rest] ->
fold(Rest, Fun(Initial, X), Fun)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 268).
-spec group(list(YX), fun((YX) -> YZ)) -> gleam@dict:dict(YZ, list(YX)).
group(List, Key) ->
fold(List, gleam@dict:new(), update_group(Key)).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 406).
-spec map_fold(list(ABV), ABX, fun((ABX, ABV) -> {ABX, ABY})) -> {ABX,
list(ABY)}.
map_fold(List, Acc, Fun) ->
_pipe = fold(
List,
{Acc, []},
fun(Acc@1, Item) ->
{Current_acc, Items} = Acc@1,
{Next_acc, Next_item} = Fun(Current_acc, Item),
{Next_acc, [Next_item | Items]}
end
),
gleam@pair:map_second(_pipe, fun lists:reverse/1).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 716).
-spec fold_right(list(AEY), AFA, fun((AFA, AEY) -> AFA)) -> AFA.
fold_right(List, Initial, Fun) ->
case List of
[] ->
Initial;
[X | Rest] ->
Fun(fold_right(Rest, Initial, Fun), X)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 727).
-spec do_index_fold(
list(AFB),
AFD,
fun((AFD, AFB, integer()) -> AFD),
integer()
) -> AFD.
do_index_fold(Over, Acc, With, Index) ->
case Over of
[] ->
Acc;
[First | Rest] ->
do_index_fold(Rest, With(Acc, First, Index), With, Index + 1)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 749).
-spec index_fold(list(AFE), AFG, fun((AFG, AFE, integer()) -> AFG)) -> AFG.
index_fold(Over, Initial, Fun) ->
do_index_fold(Over, Initial, Fun, 0).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 776).
-spec try_fold(list(AFH), AFJ, fun((AFJ, AFH) -> {ok, AFJ} | {error, AFK})) -> {ok,
AFJ} |
{error, AFK}.
try_fold(Collection, Accumulator, Fun) ->
case Collection of
[] ->
{ok, Accumulator};
[First | Rest] ->
case Fun(Accumulator, First) of
{ok, Result} ->
try_fold(Rest, Result, Fun);
{error, _} = Error ->
Error
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 815).
-spec fold_until(list(AFP), AFR, fun((AFR, AFP) -> continue_or_stop(AFR))) -> AFR.
fold_until(Collection, Accumulator, Fun) ->
case Collection of
[] ->
Accumulator;
[First | Rest] ->
case Fun(Accumulator, First) of
{continue, Next_accumulator} ->
fold_until(Rest, Next_accumulator, Fun);
{stop, B} ->
B
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 852).
-spec find(list(AFT), fun((AFT) -> boolean())) -> {ok, AFT} | {error, nil}.
find(Haystack, Is_desired) ->
case Haystack of
[] ->
{error, nil};
[X | Rest] ->
case Is_desired(X) of
true ->
{ok, X};
_ ->
find(Rest, Is_desired)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 888).
-spec find_map(list(AFX), fun((AFX) -> {ok, AFZ} | {error, any()})) -> {ok, AFZ} |
{error, nil}.
find_map(Haystack, Fun) ->
case Haystack of
[] ->
{error, nil};
[X | Rest] ->
case Fun(X) of
{ok, X@1} ->
{ok, X@1};
_ ->
find_map(Rest, Fun)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 923).
-spec all(list(AGF), fun((AGF) -> boolean())) -> boolean().
all(List, Predicate) ->
case List of
[] ->
true;
[First | Rest] ->
case Predicate(First) of
true ->
all(Rest, Predicate);
false ->
false
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 960).
-spec any(list(AGH), fun((AGH) -> boolean())) -> boolean().
any(List, Predicate) ->
case List of
[] ->
false;
[First | Rest] ->
case Predicate(First) of
true ->
true;
false ->
any(Rest, Predicate)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 971).
-spec do_zip(list(AGJ), list(AGL), list({AGJ, AGL})) -> list({AGJ, AGL}).
do_zip(Xs, Ys, Acc) ->
case {Xs, Ys} of
{[X | Xs@1], [Y | Ys@1]} ->
do_zip(Xs@1, Ys@1, [{X, Y} | Acc]);
{_, _} ->
lists:reverse(Acc)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1005).
-spec zip(list(AGP), list(AGR)) -> list({AGP, AGR}).
zip(List, Other) ->
do_zip(List, Other, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1035).
-spec strict_zip(list(AGU), list(AGW)) -> {ok, list({AGU, AGW})} | {error, nil}.
strict_zip(List, Other) ->
case erlang:length(List) =:= erlang:length(Other) of
true ->
{ok, zip(List, Other)};
false ->
{error, nil}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1045).
-spec do_unzip(list({AWT, AWU}), list(AWT), list(AWU)) -> {list(AWT), list(AWU)}.
do_unzip(Input, Xs, Ys) ->
case Input of
[] ->
{lists:reverse(Xs), lists:reverse(Ys)};
[{X, Y} | Rest] ->
do_unzip(Rest, [X | Xs], [Y | Ys])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1066).
-spec unzip(list({AHF, AHG})) -> {list(AHF), list(AHG)}.
unzip(Input) ->
do_unzip(Input, [], []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1070).
-spec do_intersperse(list(AHK), AHK, list(AHK)) -> list(AHK).
do_intersperse(List, Separator, Acc) ->
case List of
[] ->
lists:reverse(Acc);
[X | Rest] ->
do_intersperse(Rest, Separator, [X, Separator | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1093).
-spec intersperse(list(AHO), AHO) -> list(AHO).
intersperse(List, Elem) ->
case List of
[] ->
List;
[_] ->
List;
[X | Rest] ->
do_intersperse(Rest, Elem, [X])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1124).
-spec at(list(AHR), integer()) -> {ok, AHR} | {error, nil}.
at(List, Index) ->
case Index >= 0 of
true ->
_pipe = List,
_pipe@1 = drop(_pipe, Index),
first(_pipe@1);
false ->
{error, nil}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1145).
-spec unique(list(AHV)) -> list(AHV).
unique(List) ->
case List of
[] ->
[];
[X | Rest] ->
[X | unique(filter(Rest, fun(Y) -> Y /= X end))]
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1155).
-spec merge_up(
integer(),
integer(),
list(AHY),
list(AHY),
list(AHY),
fun((AHY, AHY) -> gleam@order:order())
) -> list(AHY).
merge_up(Na, Nb, A, B, Acc, Compare) ->
case {Na, Nb, A, B} of
{0, 0, _, _} ->
Acc;
{_, 0, [Ax | Ar], _} ->
merge_up(Na - 1, Nb, Ar, B, [Ax | Acc], Compare);
{0, _, _, [Bx | Br]} ->
merge_up(Na, Nb - 1, A, Br, [Bx | Acc], Compare);
{_, _, [Ax@1 | Ar@1], [Bx@1 | Br@1]} ->
case Compare(Ax@1, Bx@1) of
gt ->
merge_up(Na, Nb - 1, A, Br@1, [Bx@1 | Acc], Compare);
_ ->
merge_up(Na - 1, Nb, Ar@1, B, [Ax@1 | Acc], Compare)
end;
{_, _, _, _} ->
Acc
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1179).
-spec merge_down(
integer(),
integer(),
list(AID),
list(AID),
list(AID),
fun((AID, AID) -> gleam@order:order())
) -> list(AID).
merge_down(Na, Nb, A, B, Acc, Compare) ->
case {Na, Nb, A, B} of
{0, 0, _, _} ->
Acc;
{_, 0, [Ax | Ar], _} ->
merge_down(Na - 1, Nb, Ar, B, [Ax | Acc], Compare);
{0, _, _, [Bx | Br]} ->
merge_down(Na, Nb - 1, A, Br, [Bx | Acc], Compare);
{_, _, [Ax@1 | Ar@1], [Bx@1 | Br@1]} ->
case Compare(Bx@1, Ax@1) of
lt ->
merge_down(Na - 1, Nb, Ar@1, B, [Ax@1 | Acc], Compare);
_ ->
merge_down(Na, Nb - 1, A, Br@1, [Bx@1 | Acc], Compare)
end;
{_, _, _, _} ->
Acc
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1206).
-spec merge_sort(
list(AII),
integer(),
fun((AII, AII) -> gleam@order:order()),
boolean()
) -> list(AII).
merge_sort(L, Ln, Compare, Down) ->
N = Ln div 2,
A = L,
B = drop(L, N),
case Ln < 3 of
true ->
case Down of
true ->
merge_down(N, Ln - N, A, B, [], Compare);
false ->
merge_up(N, Ln - N, A, B, [], Compare)
end;
false ->
case Down of
true ->
merge_down(
N,
Ln - N,
merge_sort(A, N, Compare, false),
merge_sort(B, Ln - N, Compare, false),
[],
Compare
);
false ->
merge_up(
N,
Ln - N,
merge_sort(A, N, Compare, true),
merge_sort(B, Ln - N, Compare, true),
[],
Compare
)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1256).
-spec sort(list(AIL), fun((AIL, AIL) -> gleam@order:order())) -> list(AIL).
sort(List, Compare) ->
merge_sort(List, erlang:length(List), Compare, true).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1283).
-spec tail_recursive_range(integer(), integer(), list(integer())) -> list(integer()).
tail_recursive_range(Start, Stop, Acc) ->
case gleam@int:compare(Start, Stop) of
eq ->
[Stop | Acc];
gt ->
tail_recursive_range(Start, Stop + 1, [Stop | Acc]);
lt ->
tail_recursive_range(Start, Stop - 1, [Stop | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1279).
-spec range(integer(), integer()) -> list(integer()).
range(Start, Stop) ->
tail_recursive_range(Start, Stop, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1291).
-spec do_repeat(AIR, integer(), list(AIR)) -> list(AIR).
do_repeat(A, Times, Acc) ->
case Times =< 0 of
true ->
Acc;
false ->
do_repeat(A, Times - 1, [A | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1312).
-spec repeat(AIU, integer()) -> list(AIU).
repeat(A, Times) ->
do_repeat(A, Times, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1316).
-spec do_split(list(AIW), integer(), list(AIW)) -> {list(AIW), list(AIW)}.
do_split(List, N, Taken) ->
case N =< 0 of
true ->
{lists:reverse(Taken), List};
false ->
case List of
[] ->
{lists:reverse(Taken), []};
[X | Xs] ->
do_split(Xs, N - 1, [X | Taken])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1349).
-spec split(list(AJB), integer()) -> {list(AJB), list(AJB)}.
split(List, Index) ->
do_split(List, Index, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1353).
-spec do_split_while(list(AJF), fun((AJF) -> boolean()), list(AJF)) -> {list(AJF),
list(AJF)}.
do_split_while(List, F, Acc) ->
case List of
[] ->
{lists:reverse(Acc), []};
[X | Xs] ->
case F(X) of
false ->
{lists:reverse(Acc), List};
_ ->
do_split_while(Xs, F, [X | Acc])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1386).
-spec split_while(list(AJK), fun((AJK) -> boolean())) -> {list(AJK), list(AJK)}.
split_while(List, Predicate) ->
do_split_while(List, Predicate, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1418).
-spec key_find(list({AJO, AJP}), AJO) -> {ok, AJP} | {error, nil}.
key_find(Keyword_list, Desired_key) ->
find_map(
Keyword_list,
fun(Keyword) ->
{Key, Value} = Keyword,
case Key =:= Desired_key of
true ->
{ok, Value};
false ->
{error, nil}
end
end
).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1449).
-spec key_filter(list({AJT, AJU}), AJT) -> list(AJU).
key_filter(Keyword_list, Desired_key) ->
filter_map(
Keyword_list,
fun(Keyword) ->
{Key, Value} = Keyword,
case Key =:= Desired_key of
true ->
{ok, Value};
false ->
{error, nil}
end
end
).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1462).
-spec do_pop(list(BAM), fun((BAM) -> boolean()), list(BAM)) -> {ok,
{BAM, list(BAM)}} |
{error, nil}.
do_pop(Haystack, Predicate, Checked) ->
case Haystack of
[] ->
{error, nil};
[X | Rest] ->
case Predicate(X) of
true ->
{ok, {X, lists:append(lists:reverse(Checked), Rest)}};
false ->
do_pop(Rest, Predicate, [X | Checked])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1494).
-spec pop(list(AKB), fun((AKB) -> boolean())) -> {ok, {AKB, list(AKB)}} |
{error, nil}.
pop(Haystack, Is_desired) ->
do_pop(Haystack, Is_desired, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1501).
-spec do_pop_map(list(BBA), fun((BBA) -> {ok, BBN} | {error, any()}), list(BBA)) -> {ok,
{BBN, list(BBA)}} |
{error, nil}.
do_pop_map(Haystack, Mapper, Checked) ->
case Haystack of
[] ->
{error, nil};
[X | Rest] ->
case Mapper(X) of
{ok, Y} ->
{ok, {Y, lists:append(lists:reverse(Checked), Rest)}};
{error, _} ->
do_pop_map(Rest, Mapper, [X | Checked])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1534).
-spec pop_map(list(AKK), fun((AKK) -> {ok, AKM} | {error, any()})) -> {ok,
{AKM, list(AKK)}} |
{error, nil}.
pop_map(Haystack, Is_desired) ->
do_pop_map(Haystack, Is_desired, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1564).
-spec key_pop(list({AKT, AKU}), AKT) -> {ok, {AKU, list({AKT, AKU})}} |
{error, nil}.
key_pop(Haystack, Key) ->
pop_map(
Haystack,
fun(Entry) ->
{K, V} = Entry,
case K of
K@1 when K@1 =:= Key ->
{ok, V};
_ ->
{error, nil}
end
end
).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1594).
-spec key_set(list({AKZ, ALA}), AKZ, ALA) -> list({AKZ, ALA}).
key_set(List, Key, Value) ->
case List of
[] ->
[{Key, Value}];
[{K, _} | Rest] when K =:= Key ->
[{Key, Value} | Rest];
[First | Rest@1] ->
[First | key_set(Rest@1, Key, Value)]
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1615).
-spec each(list(ALD), fun((ALD) -> any())) -> nil.
each(List, F) ->
case List of
[] ->
nil;
[X | Xs] ->
F(X),
each(Xs, F)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1641).
-spec try_each(list(ALG), fun((ALG) -> {ok, any()} | {error, ALJ})) -> {ok, nil} |
{error, ALJ}.
try_each(List, Fun) ->
case List of
[] ->
{ok, nil};
[X | Xs] ->
case Fun(X) of
{ok, _} ->
try_each(Xs, Fun);
{error, E} ->
{error, E}
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1655).
-spec do_partition(list(BCU), fun((BCU) -> boolean()), list(BCU), list(BCU)) -> {list(BCU),
list(BCU)}.
do_partition(List, Categorise, Trues, Falses) ->
case List of
[] ->
{lists:reverse(Trues), lists:reverse(Falses)};
[X | Xs] ->
case Categorise(X) of
true ->
do_partition(Xs, Categorise, [X | Trues], Falses);
false ->
do_partition(Xs, Categorise, Trues, [X | Falses])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1677).
-spec partition(list(ALT), fun((ALT) -> boolean())) -> {list(ALT), list(ALT)}.
partition(List, Categorise) ->
do_partition(List, Categorise, [], []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1693).
-spec permutations(list(ALX)) -> list(list(ALX)).
permutations(L) ->
case L of
[] ->
[[]];
_ ->
_pipe = L,
_pipe@5 = index_map(_pipe, fun(I, I_idx) -> _pipe@1 = L,
_pipe@2 = index_fold(
_pipe@1,
[],
fun(Acc, J, J_idx) -> case I_idx =:= J_idx of
true ->
Acc;
false ->
[J | Acc]
end end
),
_pipe@3 = lists:reverse(_pipe@2),
_pipe@4 = permutations(_pipe@3),
map(_pipe@4, fun(Permutation) -> [I | Permutation] end) end),
concat(_pipe@5)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1714).
-spec do_window(list(list(AMB)), list(AMB), integer()) -> list(list(AMB)).
do_window(Acc, L, N) ->
Window = take(L, N),
case erlang:length(Window) =:= N of
true ->
do_window([Window | Acc], drop(L, 1), N);
false ->
Acc
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1737).
-spec window(list(AMH), integer()) -> list(list(AMH)).
window(L, N) ->
_pipe = do_window([], L, N),
lists:reverse(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1756).
-spec window_by_2(list(AML)) -> list({AML, AML}).
window_by_2(L) ->
zip(L, drop(L, 1)).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1769).
-spec drop_while(list(AMO), fun((AMO) -> boolean())) -> list(AMO).
drop_while(List, Predicate) ->
case List of
[] ->
[];
[X | Xs] ->
case Predicate(X) of
true ->
drop_while(Xs, Predicate);
false ->
[X | Xs]
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1783).
-spec do_take_while(list(AMR), fun((AMR) -> boolean()), list(AMR)) -> list(AMR).
do_take_while(List, Predicate, Acc) ->
case List of
[] ->
lists:reverse(Acc);
[First | Rest] ->
case Predicate(First) of
true ->
do_take_while(Rest, Predicate, [First | Acc]);
false ->
lists:reverse(Acc)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1807).
-spec take_while(list(AMV), fun((AMV) -> boolean())) -> list(AMV).
take_while(List, Predicate) ->
do_take_while(List, Predicate, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1814).
-spec do_chunk(list(AMY), fun((AMY) -> ANA), ANA, list(AMY), list(list(AMY))) -> list(list(AMY)).
do_chunk(List, F, Previous_key, Current_chunk, Acc) ->
case List of
[First | Rest] ->
Key = F(First),
case Key =:= Previous_key of
false ->
New_acc = [lists:reverse(Current_chunk) | Acc],
do_chunk(Rest, F, Key, [First], New_acc);
_ ->
do_chunk(Rest, F, Key, [First | Current_chunk], Acc)
end;
_ ->
lists:reverse([lists:reverse(Current_chunk) | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1846).
-spec chunk(list(ANG), fun((ANG) -> any())) -> list(list(ANG)).
chunk(List, F) ->
case List of
[] ->
[];
[First | Rest] ->
do_chunk(Rest, F, F(First), [First], [])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1853).
-spec do_sized_chunk(
list(ANL),
integer(),
integer(),
list(ANL),
list(list(ANL))
) -> list(list(ANL)).
do_sized_chunk(List, Count, Left, Current_chunk, Acc) ->
case List of
[] ->
case Current_chunk of
[] ->
lists:reverse(Acc);
Remaining ->
lists:reverse([lists:reverse(Remaining) | Acc])
end;
[First | Rest] ->
Chunk = [First | Current_chunk],
case Left > 1 of
false ->
do_sized_chunk(
Rest,
Count,
Count,
[],
[lists:reverse(Chunk) | Acc]
);
true ->
do_sized_chunk(Rest, Count, Left - 1, Chunk, Acc)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1895).
-spec sized_chunk(list(ANS), integer()) -> list(list(ANS)).
sized_chunk(List, Count) ->
do_sized_chunk(List, Count, Count, [], []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1919).
-spec reduce(list(ANW), fun((ANW, ANW) -> ANW)) -> {ok, ANW} | {error, nil}.
reduce(List, Fun) ->
case List of
[] ->
{error, nil};
[First | Rest] ->
{ok, fold(Rest, First, Fun)}
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1926).
-spec do_scan(list(AOA), AOC, list(AOC), fun((AOC, AOA) -> AOC)) -> list(AOC).
do_scan(List, Accumulator, Accumulated, Fun) ->
case List of
[] ->
lists:reverse(Accumulated);
[X | Xs] ->
Next = Fun(Accumulator, X),
do_scan(Xs, Next, [Next | Accumulated], Fun)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1950).
-spec scan(list(AOF), AOH, fun((AOH, AOF) -> AOH)) -> list(AOH).
scan(List, Initial, Fun) ->
do_scan(List, Initial, [], Fun).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1978).
-spec last(list(AOJ)) -> {ok, AOJ} | {error, nil}.
last(List) ->
_pipe = List,
reduce(_pipe, fun(_, Elem) -> Elem end).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1997).
-spec combinations(list(AON), integer()) -> list(list(AON)).
combinations(Items, N) ->
case N of
0 ->
[[]];
_ ->
case Items of
[] ->
[];
[X | Xs] ->
First_combinations = begin
_pipe = map(
combinations(Xs, N - 1),
fun(Com) -> [X | Com] end
),
lists:reverse(_pipe)
end,
fold(
First_combinations,
combinations(Xs, N),
fun(Acc, C) -> [C | Acc] end
)
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2015).
-spec do_combination_pairs(list(AOR)) -> list(list({AOR, AOR})).
do_combination_pairs(Items) ->
case Items of
[] ->
[];
[X | Xs] ->
First_combinations = map(Xs, fun(Other) -> {X, Other} end),
[First_combinations | do_combination_pairs(Xs)]
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2034).
-spec combination_pairs(list(AOV)) -> list({AOV, AOV}).
combination_pairs(Items) ->
_pipe = do_combination_pairs(Items),
concat(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2066).
-spec transpose(list(list(APC))) -> list(list(APC)).
transpose(List_of_list) ->
Take_first = fun(List) -> case List of
[] ->
[];
[F] ->
[F];
[F@1 | _] ->
[F@1]
end end,
case List_of_list of
[] ->
[];
[[] | Xss] ->
transpose(Xss);
Rows ->
Firsts = begin
_pipe = Rows,
_pipe@1 = map(_pipe, Take_first),
concat(_pipe@1)
end,
Rest = transpose(map(Rows, fun(_capture) -> drop(_capture, 1) end)),
[Firsts | Rest]
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2048).
-spec interleave(list(list(AOY))) -> list(AOY).
interleave(List) ->
_pipe = transpose(List),
concat(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2089).
-spec do_shuffle_pair_unwrap(list({float(), APH}), list(APH)) -> list(APH).
do_shuffle_pair_unwrap(List, Acc) ->
case List of
[] ->
Acc;
[Elem_pair | Enumerable] ->
do_shuffle_pair_unwrap(
Enumerable,
[erlang:element(2, Elem_pair) | Acc]
)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2097).
-spec do_shuffle_by_pair_indexes(list({float(), APL})) -> list({float(), APL}).
do_shuffle_by_pair_indexes(List_of_pairs) ->
sort(
List_of_pairs,
fun(A_pair, B_pair) ->
gleam@float:compare(
erlang:element(1, A_pair),
erlang:element(1, B_pair)
)
end
).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2116).
-spec shuffle(list(APO)) -> list(APO).
shuffle(List) ->
_pipe = List,
_pipe@1 = fold(_pipe, [], fun(Acc, A) -> [{rand:uniform(), A} | Acc] end),
_pipe@2 = do_shuffle_by_pair_indexes(_pipe@1),
do_shuffle_pair_unwrap(_pipe@2, []).