Packages
otpbp
4.72.2
7.18.0
7.16.1
7.15.0
7.14.0
7.13.0
7.12.0
7.11.0
7.10.2
7.9.3
7.9.2
7.9.1
7.8.7
7.8.6
7.8.5
7.8.4
7.7.1
7.7.0
7.6.3
7.6.2
7.6.1
7.6.0
7.5.1
7.5.0
7.4.0
7.3.4
7.3.3
7.3.2
7.3.1
7.3.0
7.2.0
7.1.1
7.1.0
7.0.4
7.0.3
7.0.2
7.0.1
6.26.0
6.25.0
6.24.0
6.23.0
6.22.2
6.21.3
6.21.2
6.21.1
6.20.2
6.19.1
6.19.0
6.18.3
6.18.2
6.18.1
6.18.0
6.17.1
6.17.0
6.16.0
6.15.4
6.15.3
6.15.2
6.15.1
6.15.0
6.14.0
6.13.5
6.13.4
6.13.3
6.13.2
6.13.1
6.13.0
6.12.0
6.11.2
6.11.1
6.10.0
6.9.2
6.9.1
6.9.0
6.8.0
6.7.1
6.7.0
6.6.4
6.6.3
6.6.2
6.6.1
6.6.0
6.5.0
6.4.0
6.3.3
6.3.2
6.3.1
6.3.0
6.2.1
6.2.0
6.1.0
6.0.0
5.39.0
5.38.0
5.37.0
5.36.0
5.35.2
5.34.3
5.34.2
5.34.1
5.33.1
5.32.1
5.32.0
5.31.3
5.31.2
5.31.1
5.31.0
5.30.1
5.30.0
5.29.0
5.28.4
5.28.3
5.28.2
5.28.1
5.28.0
5.27.0
5.26.5
5.26.4
5.26.3
5.26.2
5.26.1
5.26.0
5.25.0
5.24.2
5.24.1
5.23.0
5.22.2
5.22.1
5.22.0
5.21.0
5.20.1
5.20.0
5.19.4
5.19.3
5.19.2
5.19.1
5.19.0
5.18.0
5.17.0
5.16.3
5.16.1
5.16.0
5.15.1
5.15.0
5.14.0
5.13.1
5.13.0
5.12.1
5.12.0
5.11.2
5.11.1
5.10.1
5.10.0
5.9.0
5.8.0
5.7.0
5.6.1
5.6.0
5.5.0
5.4.2
5.4.1
5.4.0
5.3.0
5.2.2
5.2.1
5.2.0
5.1.2
5.1.1
4.79.0
4.78.0
4.77.0
4.76.2
4.75.3
4.75.2
4.75.1
4.74.0
4.73.1
4.73.0
4.72.3
4.72.2
4.72.1
4.72.0
4.71.1
4.71.0
4.70.0
4.69.4
4.69.3
4.69.2
4.69.1
4.69.0
4.68.0
4.67.5
4.67.4
4.67.3
4.67.2
4.67.0
4.66.0
4.65.2
4.65.1
4.64.0
4.63.2
4.63.1
4.63.0
4.62.0
4.61.1
4.61.0
4.60.4
4.60.3
4.60.2
4.60.1
4.60.0
4.59.0
4.58.0
4.57.2
4.57.1
4.57.0
4.56.2
4.56.1
4.56.0
4.55.0
4.54.0
4.53.0
4.52.1
4.52.0
4.51.3
4.51.2
4.51.0
4.50.0
4.49.3
4.49.2
OTP backports
Current section
Files
Jump to
Current section
Files
src/otpbp_lists.erl
-module(otpbp_lists).
-ifndef(HAVE_lists__join_2).
% OTP 19.0
-export([join/2]).
-endif.
-ifndef(HAVE_lists__search_2).
% OTP 21.0
-export([search/2]).
-endif.
-ifndef(HAVE_lists__enumerate_1).
% OTP 25.0
-export([enumerate/1]).
-endif.
-ifndef(HAVE_lists__enumerate_2).
% OTP 25.0
-export([enumerate/2]).
-endif.
-ifndef(HAVE_lists__enumerate_3).
% OTP 26.0
-export([enumerate/3]).
-endif.
-ifndef(HAVE_lists__uniq_1).
% OTP 25.0
-export([uniq/1]).
-endif.
-ifndef(HAVE_lists__uniq_2).
% OTP 25.0
-export([uniq/2]).
-endif.
-ifndef(HAVE_lists__zip_3).
% OTP 26.0
-export([zip/3]).
-endif.
-ifndef(HAVE_lists__zip3_4).
% OTP 26.0
-export([zip3/4]).
-endif.
-ifndef(HAVE_lists__zipwith_4).
% OTP 26.0
-export([zipwith/4]).
-endif.
-ifndef(HAVE_lists__zipwith3_5).
% OTP 26.0
-export([zipwith3/5]).
-endif.
-ifndef(HAVE_lists__enumerate_1).
-ifdef(HAVE_lists__enumerate_2).
-import(lists, [enumerate/2]).
-endif.
-endif.
-ifndef(HAVE_lists__enumerate_2).
-ifdef(HAVE_lists__enumerate_3).
-import(lists, [enumerate/3]).
-endif.
-endif.
-ifndef(HAVE_lists__join_2).
join(_, []) -> [];
join(Sep, [H|T]) -> [H|join_prepend(Sep, T)].
join_prepend(_, []) -> [];
join_prepend(Sep, [H|T]) -> [Sep, H|join_prepend(Sep, T)].
-endif.
-ifndef(HAVE_lists__search_2).
search(F, [H|T]) ->
case F(H) of
true -> {value, H};
false -> search(F, T)
end;
search(F, []) when is_function(F, 1) -> false.
-endif.
-ifndef(HAVE_lists__enumerate_1).
enumerate(List) -> enumerate(1, List).
-endif.
-ifndef(HAVE_lists__enumerate_2).
enumerate(Index, List) -> enumerate(Index, 1, List).
-endif.
-ifndef(HAVE_lists__enumerate_3).
enumerate(Index, Step, List) when is_integer(Index), is_integer(Step) ->
{L, _} = lists:mapfoldl(fun(E, A) -> {{A, E}, A + Step} end, Index, List),
L.
-endif.
-ifndef(HAVE_lists__uniq_1).
uniq(L) -> uniq_1(L, #{}).
uniq_1([X|Xs], M) ->
case maps:is_key(X, M) of
true -> uniq_1(Xs, M);
false -> [X|uniq_1(Xs, M#{X => true})]
end;
uniq_1([], _) -> [].
-endif.
-ifndef(HAVE_lists__uniq_2).
uniq(F, L) when is_function(F, 1) -> uniq_2(L, F, #{}).
uniq_2([X|Xs], F, M) ->
Key = F(X),
case maps:is_key(Key, M) of
true -> uniq_2(Xs, F, M);
false -> [X|uniq_2(Xs, F, M#{Key => true})]
end;
uniq_2([], _, _) -> [].
-endif.
-ifndef(HAVE_lists__zip_3).
zip(Xs, Ys, fail) -> lists:zip(Xs, Ys);
zip(Xs, Ys, trim) -> zip(Xs, Ys);
zip(Xs, Ys, {pad, {X, Y}}) -> zip(Xs, Ys, X, Y).
zip([X|Xs], [Y|Ys]) -> [{X, Y}|zip(Xs, Ys)];
zip(Xs, Ys) when is_list(Xs), is_list(Ys) -> [].
zip([X|Xs], [Y|Ys], PX, PY) -> [{X, Y}|zip(Xs, Ys, PX, PY)];
zip([], [], _, _) -> [];
zip([], [_|_] = Ys, PX, _) -> [{PX, Y} || Y <- Ys];
zip([_|_] = Xs, [], _, PY) -> [{X, PY} || X <- Xs].
-endif.
-ifndef(HAVE_lists__zip3_4).
zip3(Xs, Ys, Zs, fail) -> lists:zip3(Xs, Ys, Zs);
zip3(Xs, Ys, Zs, trim) -> zip3(Xs, Ys, Zs);
zip3(Xs, Ys, Zs, {pad, {X, Y, Z}}) -> zip3(Xs, Ys, Zs, X, Y, Z).
zip3([X|Xs], [Y|Ys], [Z|Zs]) -> [{X, Y, Z}|zip3(Xs, Ys, Zs)];
zip3(Xs, Ys, Zs) when is_list(Xs), is_list(Ys), is_list(Zs) -> [].
zip3([X|Xs], [Y|Ys], [Z|Zs], PX, PY, PZ) -> [{X, Y, Z}|zip3(Xs, Ys, Zs, PX, PY, PZ)];
zip3([], [], [], _, _, _) -> [];
zip3([], [], [_|_] = Zs, PX, PY, _) -> [{PX, PY, Z} || Z <- Zs];
zip3([], [_|_] = Ys, [], PX, _, PZ) -> [{PX, Y, PZ} || Y <- Ys];
zip3([_|_] = Xs, [], [], _, PY, PZ) -> [{X, PY, PZ} || X <- Xs];
zip3([], [Y|Ys], [Z|Zs], PX, PY, PZ) -> [{PX, Y, Z}|zip3([], Ys, Zs, PX, PY, PZ)];
zip3([X|Xs], [], [Z|Zs], PX, PY, PZ) -> [{X, PY, Z}|zip3(Xs, [], Zs, PX, PY, PZ)];
zip3([X|Xs], [Y|Ys], [], PX, PY, PZ) -> [{X, Y, PZ}|zip3(Xs, Ys, [], PX, PY, PZ)].
-endif.
-ifndef(HAVE_lists__zipwith_4).
zipwith(F, Xs, Ys, fail) -> lists:zipwith(F, Xs, Ys);
zipwith(F, Xs, Ys, trim) -> zipwith(F, Xs, Ys);
zipwith(F, Xs, Ys, {pad, {X, Y}}) -> zipwith(F, Xs, Ys, X, Y).
zipwith(F, [X|Xs], [Y|Ys]) -> [F(X, Y)|zipwith(F, Xs, Ys)];
zipwith(F, Xs, Ys) when is_function(F, 2), is_list(Xs), is_list(Ys) -> [].
zipwith(F, [X|Xs], [Y|Ys], PX, PY) -> [F(X, Y)|zipwith(F, Xs, Ys, PX, PY)];
zipwith(F, [], [], _, _) when is_function(F, 2) -> [];
zipwith(F, [], [_|_] = Ys, X, _) -> [F(X, Y) || Y <- Ys];
zipwith(F, [_|_] = Xs, [], _, Y) -> [F(X, Y) || X <- Xs].
-endif.
-ifndef(HAVE_lists__zipwith3_5).
zipwith3(F, Xs, Ys, Zs, fail) -> lists:zipwith3(F, Xs, Ys, Zs);
zipwith3(F, Xs, Ys, Zs, trim) -> zipwith3(F, Xs, Ys, Zs);
zipwith3(F, Xs, Ys, Zs, {pad, {X, Y, Z}}) -> zipwith3(F, Xs, Ys, Zs, X, Y, Z).
zipwith3(F, [X|Xs], [Y|Ys], [Z|Zs]) -> [F(X, Y, Z)|zipwith3(F, Xs, Ys, Zs)];
zipwith3(F, Xs, Ys, Zs) when is_function(F, 3), is_list(Xs), is_list(Ys), is_list(Zs) -> [].
zipwith3(F, [X|Xs], [Y|Ys], [Z|Zs], PX, PY, PZ) -> [F(X, Y, Z)|zipwith3(F, Xs, Ys, Zs, PX, PY, PZ)];
zipwith3(F, [], [], [], _, _, _) when is_function(F, 3) -> [];
zipwith3(F, [], [], [_|_] = Zs, X, Y, _) -> [F(X, Y, Z) || Z <- Zs];
zipwith3(F, [], [_|_] = Ys, [], X, _, Z) -> [F(X, Y, Z) || Y <- Ys];
zipwith3(F, [_|_] = Xs, [], [], _, Y, Z) -> [F(X, Y, Z) || X <- Xs];
zipwith3(F, [], [Y|Ys], [Z|Zs], PX, PY, PZ) -> [F(PX, Y, Z)|zipwith3(F, [], Ys, Zs, PX, PY, PZ)];
zipwith3(F, [X|Xs], [], [Z|Zs], PX, PY, PZ) -> [F(X, PY, Z)|zipwith3(F, Xs, [], Zs, PX, PY, PZ)];
zipwith3(F, [X|Xs], [Y|Ys], [], PX, PY, PZ) -> [F(X, Y, PZ)|zipwith3(F, Xs, Ys, [], PX, PY, PZ)].
-endif.