Skip to content

Commit

Permalink
Add desc_collate_with/2.
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Dec 15, 2012
1 parent c6028e1 commit 7a62305
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lists2.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
filter_head/2, filter_head/2,
cmap/2, cmap/2,
cmap/3, cmap/3,
collate_with/2]). collate_with/2,
desc_collate_with/2]).




%% @doc It is like `lists:sublist/1', BUT uses a tuple field for comparation. %% @doc It is like `lists:sublist/1', BUT uses a tuple field for comparation.
Expand Down Expand Up @@ -270,6 +271,11 @@ seq_group_with2(_KeyMaker, [], Key, Acc) ->
[{Key, lists:reverse(Acc)}]. [{Key, lists:reverse(Acc)}].





%% @doc Collate in ascending order using a key maker.
collate_with(KeyMaker, List) -> collate_with(KeyMaker, List) ->
lists:sort(fun(X, Y) -> KeyMaker(X) < KeyMaker(Y) end, List). lists:sort(fun(X, Y) -> KeyMaker(X) < KeyMaker(Y) end, List).


%% @doc Collate in descending order using a key maker.
desc_collate_with(KeyMaker, List) ->
lists:sort(fun(X, Y) -> KeyMaker(X) > KeyMaker(Y) end, List).

0 comments on commit 7a62305

Please sign in to comment.