Skip to content

Commit

Permalink
otpbp_lists: shrink enumerate/1, enumerate/2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ledest committed Dec 10, 2023
1 parent 5dee3f5 commit 0c34246
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/otpbp_lists.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
-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__search_2).
search(F, [H|T]) ->
case F(H) of
Expand All @@ -51,15 +62,11 @@ search(F, []) when is_function(F, 1) -> false.
-endif.

-ifndef(HAVE_lists__enumerate_1).
enumerate(List) ->
{L, _} = lists:mapfoldl(fun(E, A) -> {{A, E}, A + 1} end, 1, List),
L.
enumerate(List) -> enumerate(1, List).
-endif.

-ifndef(HAVE_lists__enumerate_2).
enumerate(Index, List) when is_integer(Index) ->
{L, _} = lists:mapfoldl(fun(E, A) -> {{A, E}, A + 1} end, Index, List),
L.
enumerate(Index, List) -> enumerate(Index, 1, List).
-endif.

-ifndef(HAVE_lists__enumerate_3).
Expand Down

0 comments on commit 0c34246

Please sign in to comment.