Packages

A fork of the Gleam standard library for Glistix's Nix target

Current section

Files

Jump to
glistix_stdlib src gleam@list.erl
Raw

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, wrap/1, 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, 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, sorting/0]).
-type continue_or_stop(AAB) :: {continue, AAB} | {stop, AAB}.
-type sorting() :: ascending | descending.
-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(ARW), list(ARW)) -> list(ARW).
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(AAG)) -> list(AAG).
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(AAO), AAO) -> 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(AAQ)) -> {ok, AAQ} | {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(AAU)) -> {ok, list(AAU)} | {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((AAZ) -> ABA)) -> fun((gleam@dict:dict(ABA, list(AAZ)), AAZ) -> gleam@dict:dict(ABA, list(AAZ))).
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", 273).
-spec do_filter(list(ABN), fun((ABN) -> boolean()), list(ABN)) -> list(ABN).
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", 301).
-spec filter(list(ABR), fun((ABR) -> boolean())) -> list(ABR).
filter(List, Predicate) ->
do_filter(List, Predicate, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 305).
-spec do_filter_map(
list(ABU),
fun((ABU) -> {ok, ABW} | {error, any()}),
list(ABW)
) -> list(ABW).
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", 337).
-spec filter_map(list(ACC), fun((ACC) -> {ok, ACE} | {error, any()})) -> list(ACE).
filter_map(List, Fun) ->
do_filter_map(List, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 341).
-spec do_map(list(ACJ), fun((ACJ) -> ACL), list(ACL)) -> list(ACL).
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", 358).
-spec map(list(ACO), fun((ACO) -> ACQ)) -> list(ACQ).
map(List, Fun) ->
do_map(List, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 382).
-spec do_map2(list(ACY), list(ADA), fun((ACY, ADA) -> ADC), list(ADC)) -> list(ADC).
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", 378).
-spec map2(list(ACS), list(ACU), fun((ACS, ACU) -> ACW)) -> list(ACW).
map2(List1, List2, Fun) ->
do_map2(List1, List2, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 420).
-spec do_index_map(
list(ADK),
fun((ADK, integer()) -> ADM),
integer(),
list(ADM)
) -> list(ADM).
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", 448).
-spec index_map(list(ADP), fun((ADP, integer()) -> ADR)) -> list(ADR).
index_map(List, Fun) ->
do_index_map(List, Fun, 0, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 452).
-spec do_try_map(list(ADT), fun((ADT) -> {ok, ADV} | {error, ADW}), list(ADV)) -> {ok,
list(ADV)} |
{error, ADW}.
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", 499).
-spec try_map(list(AED), fun((AED) -> {ok, AEF} | {error, AEG})) -> {ok,
list(AEF)} |
{error, AEG}.
try_map(List, Fun) ->
do_try_map(List, Fun, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 526).
-spec drop(list(AEM), integer()) -> list(AEM).
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", 537).
-spec do_take(list(AEP), integer(), list(AEP)) -> list(AEP).
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", 568).
-spec take(list(AET), integer()) -> list(AET).
take(List, N) ->
do_take(List, N, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 581).
-spec new() -> list(any()).
new() ->
[].
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 601).
-spec wrap(AEY) -> list(AEY).
wrap(Item) ->
[Item].
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 622).
-spec do_append(list(AFE), list(AFE)) -> list(AFE).
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", 618).
-spec append(list(AFA), list(AFA)) -> list(AFA).
append(First, Second) ->
lists:append(First, Second).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 642).
-spec prepend(list(AFI), AFI) -> list(AFI).
prepend(List, Item) ->
[Item | List].
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 647).
-spec reverse_and_prepend(list(AFL), list(AFL)) -> list(AFL).
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", 654).
-spec do_concat(list(list(AFP)), list(AFP)) -> list(AFP).
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", 673).
-spec concat(list(list(AFU))) -> list(AFU).
concat(Lists) ->
do_concat(Lists, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 689).
-spec flatten(list(list(AFY))) -> list(AFY).
flatten(Lists) ->
do_concat(Lists, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 702).
-spec flat_map(list(AGC), fun((AGC) -> list(AGE))) -> list(AGE).
flat_map(List, Fun) ->
_pipe = map(List, Fun),
concat(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 715).
-spec fold(list(AGH), AGJ, fun((AGJ, AGH) -> AGJ)) -> AGJ.
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", 269).
-spec group(list(ABH), fun((ABH) -> ABJ)) -> gleam@dict:dict(ABJ, list(ABH)).
group(List, Key) ->
fold(List, gleam@dict:new(), update_group(Key)).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 407).
-spec map_fold(list(ADF), ADH, fun((ADH, ADF) -> {ADH, ADI})) -> {ADH,
list(ADI)}.
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", 737).
-spec fold_right(list(AGK), AGM, fun((AGM, AGK) -> AGM)) -> AGM.
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", 748).
-spec do_index_fold(
list(AGN),
AGP,
fun((AGP, AGN, integer()) -> AGP),
integer()
) -> AGP.
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", 770).
-spec index_fold(list(AGQ), AGS, fun((AGS, AGQ, integer()) -> AGS)) -> AGS.
index_fold(Over, Initial, Fun) ->
do_index_fold(Over, Initial, Fun, 0).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 797).
-spec try_fold(list(AGT), AGV, fun((AGV, AGT) -> {ok, AGV} | {error, AGW})) -> {ok,
AGV} |
{error, AGW}.
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", 836).
-spec fold_until(list(AHB), AHD, fun((AHD, AHB) -> continue_or_stop(AHD))) -> AHD.
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", 873).
-spec find(list(AHF), fun((AHF) -> boolean())) -> {ok, AHF} | {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", 909).
-spec find_map(list(AHJ), fun((AHJ) -> {ok, AHL} | {error, any()})) -> {ok, AHL} |
{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", 944).
-spec all(list(AHR), fun((AHR) -> 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", 981).
-spec any(list(AHT), fun((AHT) -> 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", 992).
-spec do_zip(list(AHV), list(AHX), list({AHV, AHX})) -> list({AHV, AHX}).
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", 1026).
-spec zip(list(AIB), list(AID)) -> list({AIB, AID}).
zip(List, Other) ->
do_zip(List, Other, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1056).
-spec strict_zip(list(AIG), list(AII)) -> {ok, list({AIG, AII})} | {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", 1066).
-spec do_unzip(list({AYW, AYX}), list(AYW), list(AYX)) -> {list(AYW), list(AYX)}.
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", 1087).
-spec unzip(list({AIR, AIS})) -> {list(AIR), list(AIS)}.
unzip(Input) ->
do_unzip(Input, [], []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1091).
-spec do_intersperse(list(AIW), AIW, list(AIW)) -> list(AIW).
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", 1114).
-spec intersperse(list(AJA), AJA) -> list(AJA).
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", 1132).
-spec unique(list(AJD)) -> list(AJD).
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", 1213).
-spec sequences(
list(AJJ),
fun((AJJ, AJJ) -> gleam@order:order()),
list(AJJ),
sorting(),
AJJ,
list(list(AJJ))
) -> list(list(AJJ)).
sequences(List, Compare, Growing, Direction, Prev, Acc) ->
Growing@1 = [Prev | Growing],
case List of
[] ->
case Direction of
ascending ->
[do_reverse(Growing@1, []) | Acc];
descending ->
[Growing@1 | Acc]
end;
[New | Rest] ->
case {Compare(Prev, New), Direction} of
{gt, descending} ->
sequences(Rest, Compare, Growing@1, Direction, New, Acc);
{lt, ascending} ->
sequences(Rest, Compare, Growing@1, Direction, New, Acc);
{eq, ascending} ->
sequences(Rest, Compare, Growing@1, Direction, New, Acc);
{gt, ascending} ->
Acc@1 = case Direction of
ascending ->
[do_reverse(Growing@1, []) | Acc];
descending ->
[Growing@1 | Acc]
end,
case Rest of
[] ->
[[New] | Acc@1];
[Next | Rest@1] ->
Direction@1 = case Compare(New, Next) of
lt ->
ascending;
eq ->
ascending;
gt ->
descending
end,
sequences(
Rest@1,
Compare,
[New],
Direction@1,
Next,
Acc@1
)
end;
{lt, descending} ->
Acc@1 = case Direction of
ascending ->
[do_reverse(Growing@1, []) | Acc];
descending ->
[Growing@1 | Acc]
end,
case Rest of
[] ->
[[New] | Acc@1];
[Next | Rest@1] ->
Direction@1 = case Compare(New, Next) of
lt ->
ascending;
eq ->
ascending;
gt ->
descending
end,
sequences(
Rest@1,
Compare,
[New],
Direction@1,
Next,
Acc@1
)
end;
{eq, descending} ->
Acc@1 = case Direction of
ascending ->
[do_reverse(Growing@1, []) | Acc];
descending ->
[Growing@1 | Acc]
end,
case Rest of
[] ->
[[New] | Acc@1];
[Next | Rest@1] ->
Direction@1 = case Compare(New, Next) of
lt ->
ascending;
eq ->
ascending;
gt ->
descending
end,
sequences(
Rest@1,
Compare,
[New],
Direction@1,
Next,
Acc@1
)
end
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1361).
-spec merge_ascendings(
list(AKG),
list(AKG),
fun((AKG, AKG) -> gleam@order:order()),
list(AKG)
) -> list(AKG).
merge_ascendings(List1, List2, Compare, Acc) ->
case {List1, List2} of
{[], List} ->
do_reverse(List, Acc);
{List, []} ->
do_reverse(List, Acc);
{[First1 | Rest1], [First2 | Rest2]} ->
case Compare(First1, First2) of
lt ->
merge_ascendings(Rest1, List2, Compare, [First1 | Acc]);
gt ->
merge_ascendings(List1, Rest2, Compare, [First2 | Acc]);
eq ->
merge_ascendings(List1, Rest2, Compare, [First2 | Acc])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1314).
-spec merge_ascending_pairs(
list(list(AJU)),
fun((AJU, AJU) -> gleam@order:order()),
list(list(AJU))
) -> list(list(AJU)).
merge_ascending_pairs(Sequences, Compare, Acc) ->
case Sequences of
[] ->
do_reverse(Acc, []);
[Sequence] ->
do_reverse([do_reverse(Sequence, []) | Acc], []);
[Ascending1, Ascending2 | Rest] ->
Descending = merge_ascendings(Ascending1, Ascending2, Compare, []),
merge_ascending_pairs(Rest, Compare, [Descending | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1388).
-spec merge_descendings(
list(AKL),
list(AKL),
fun((AKL, AKL) -> gleam@order:order()),
list(AKL)
) -> list(AKL).
merge_descendings(List1, List2, Compare, Acc) ->
case {List1, List2} of
{[], List} ->
do_reverse(List, Acc);
{List, []} ->
do_reverse(List, Acc);
{[First1 | Rest1], [First2 | Rest2]} ->
case Compare(First1, First2) of
lt ->
merge_descendings(List1, Rest2, Compare, [First2 | Acc]);
gt ->
merge_descendings(Rest1, List2, Compare, [First1 | Acc]);
eq ->
merge_descendings(Rest1, List2, Compare, [First1 | Acc])
end
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1336).
-spec merge_descending_pairs(
list(list(AKA)),
fun((AKA, AKA) -> gleam@order:order()),
list(list(AKA))
) -> list(list(AKA)).
merge_descending_pairs(Sequences, Compare, Acc) ->
case Sequences of
[] ->
do_reverse(Acc, []);
[Sequence] ->
do_reverse([do_reverse(Sequence, []) | Acc], []);
[Descending1, Descending2 | Rest] ->
Ascending = merge_descendings(Descending1, Descending2, Compare, []),
merge_descending_pairs(Rest, Compare, [Ascending | Acc])
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1280).
-spec merge_all(
list(list(AJQ)),
sorting(),
fun((AJQ, AJQ) -> gleam@order:order())
) -> list(AJQ).
merge_all(Sequences, Direction, Compare) ->
case {Sequences, Direction} of
{[], _} ->
[];
{[Sequence], ascending} ->
Sequence;
{[Sequence@1], descending} ->
do_reverse(Sequence@1, []);
{_, ascending} ->
Sequences@1 = merge_ascending_pairs(Sequences, Compare, []),
merge_all(Sequences@1, descending, Compare);
{_, descending} ->
Sequences@2 = merge_descending_pairs(Sequences, Compare, []),
merge_all(Sequences@2, ascending, Compare)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1151).
-spec sort(list(AJG), fun((AJG, AJG) -> gleam@order:order())) -> list(AJG).
sort(List, Compare) ->
case List of
[] ->
[];
[X] ->
[X];
[X@1, Y | Rest] ->
Direction = case Compare(X@1, Y) of
lt ->
ascending;
eq ->
ascending;
gt ->
descending
end,
Sequences = sequences(Rest, Compare, [X@1], Direction, Y, []),
merge_all(Sequences, ascending, Compare)
end.
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1428).
-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", 1424).
-spec range(integer(), integer()) -> list(integer()).
range(Start, Stop) ->
tail_recursive_range(Start, Stop, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1436).
-spec do_repeat(AKT, integer(), list(AKT)) -> list(AKT).
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", 1457).
-spec repeat(AKW, integer()) -> list(AKW).
repeat(A, Times) ->
do_repeat(A, Times, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1461).
-spec do_split(list(AKY), integer(), list(AKY)) -> {list(AKY), list(AKY)}.
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", 1494).
-spec split(list(ALD), integer()) -> {list(ALD), list(ALD)}.
split(List, Index) ->
do_split(List, Index, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1498).
-spec do_split_while(list(ALH), fun((ALH) -> boolean()), list(ALH)) -> {list(ALH),
list(ALH)}.
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", 1531).
-spec split_while(list(ALM), fun((ALM) -> boolean())) -> {list(ALM), list(ALM)}.
split_while(List, Predicate) ->
do_split_while(List, Predicate, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1563).
-spec key_find(list({ALQ, ALR}), ALQ) -> {ok, ALR} | {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", 1594).
-spec key_filter(list({ALV, ALW}), ALV) -> list(ALW).
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", 1607).
-spec do_pop(list(BDX), fun((BDX) -> boolean()), list(BDX)) -> {ok,
{BDX, list(BDX)}} |
{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", 1639).
-spec pop(list(AMD), fun((AMD) -> boolean())) -> {ok, {AMD, list(AMD)}} |
{error, nil}.
pop(Haystack, Is_desired) ->
do_pop(Haystack, Is_desired, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1646).
-spec do_pop_map(list(BEL), fun((BEL) -> {ok, BEY} | {error, any()}), list(BEL)) -> {ok,
{BEY, list(BEL)}} |
{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", 1679).
-spec pop_map(list(AMM), fun((AMM) -> {ok, AMO} | {error, any()})) -> {ok,
{AMO, list(AMM)}} |
{error, nil}.
pop_map(Haystack, Is_desired) ->
do_pop_map(Haystack, Is_desired, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1709).
-spec key_pop(list({AMV, AMW}), AMV) -> {ok, {AMW, list({AMV, AMW})}} |
{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", 1739).
-spec key_set(list({ANB, ANC}), ANB, ANC) -> list({ANB, ANC}).
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", 1761).
-spec each(list(ANF), fun((ANF) -> 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", 1787).
-spec try_each(list(ANI), fun((ANI) -> {ok, any()} | {error, ANL})) -> {ok, nil} |
{error, ANL}.
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", 1801).
-spec do_partition(list(BGF), fun((BGF) -> boolean()), list(BGF), list(BGF)) -> {list(BGF),
list(BGF)}.
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", 1824).
-spec partition(list(ANV), fun((ANV) -> boolean())) -> {list(ANV), list(ANV)}.
partition(List, Categorise) ->
do_partition(List, Categorise, [], []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1840).
-spec permutations(list(ANZ)) -> list(list(ANZ)).
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", 1861).
-spec do_window(list(list(AOD)), list(AOD), integer()) -> list(list(AOD)).
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", 1884).
-spec window(list(AOJ), integer()) -> list(list(AOJ)).
window(L, N) ->
_pipe = do_window([], L, N),
lists:reverse(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1903).
-spec window_by_2(list(AON)) -> list({AON, AON}).
window_by_2(L) ->
zip(L, drop(L, 1)).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1916).
-spec drop_while(list(AOQ), fun((AOQ) -> boolean())) -> list(AOQ).
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", 1930).
-spec do_take_while(list(AOT), fun((AOT) -> boolean()), list(AOT)) -> list(AOT).
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", 1954).
-spec take_while(list(AOX), fun((AOX) -> boolean())) -> list(AOX).
take_while(List, Predicate) ->
do_take_while(List, Predicate, []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 1961).
-spec do_chunk(list(APA), fun((APA) -> APC), APC, list(APA), list(list(APA))) -> list(list(APA)).
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", 1993).
-spec chunk(list(API), fun((API) -> any())) -> list(list(API)).
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", 2000).
-spec do_sized_chunk(
list(APN),
integer(),
integer(),
list(APN),
list(list(APN))
) -> list(list(APN)).
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", 2042).
-spec sized_chunk(list(APU), integer()) -> list(list(APU)).
sized_chunk(List, Count) ->
do_sized_chunk(List, Count, Count, [], []).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2066).
-spec reduce(list(APY), fun((APY, APY) -> APY)) -> {ok, APY} | {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", 2073).
-spec do_scan(list(AQC), AQE, list(AQE), fun((AQE, AQC) -> AQE)) -> list(AQE).
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", 2097).
-spec scan(list(AQH), AQJ, fun((AQJ, AQH) -> AQJ)) -> list(AQJ).
scan(List, Initial, Fun) ->
do_scan(List, Initial, [], Fun).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2125).
-spec last(list(AQL)) -> {ok, AQL} | {error, nil}.
last(List) ->
_pipe = List,
reduce(_pipe, fun(_, Elem) -> Elem end).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2144).
-spec combinations(list(AQP), integer()) -> list(list(AQP)).
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", 2162).
-spec do_combination_pairs(list(AQT)) -> list(list({AQT, AQT})).
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", 2181).
-spec combination_pairs(list(AQX)) -> list({AQX, AQX}).
combination_pairs(Items) ->
_pipe = do_combination_pairs(Items),
concat(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2213).
-spec transpose(list(list(ARE))) -> list(list(ARE)).
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", 2195).
-spec interleave(list(list(ARA))) -> list(ARA).
interleave(List) ->
_pipe = transpose(List),
concat(_pipe).
-file("/home/pgbiel/GitHub/glistix_stdlib/src/gleam/list.gleam", 2236).
-spec do_shuffle_pair_unwrap(list({float(), ARJ}), list(ARJ)) -> list(ARJ).
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", 2244).
-spec do_shuffle_by_pair_indexes(list({float(), ARN})) -> list({float(), ARN}).
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", 2263).
-spec shuffle(list(ARQ)) -> list(ARQ).
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, []).