There are proposals for a number of new functions in the lists
module in stdlib
.
For adding new functions in lists and other stdlib modules a number of criteria must be fulfilled:
- There must be convincing and common enough uses case where use of the new function will make a difference i terms of better, shorter, nicer easier to understand code.
- The function as such is known from other languages libraries and kind of expected in a standard library.
- The functions fits in the suggested module and follows the same principles as other functions in that module.
This is a request focusing on use cases for the proposed functions. So please send us
use cases with examples and motivation.
For example snippets of existing code and how it can be rewritten in a nicer way with the use of one of the proposed functions.
Other Pros and Cons for the functions are also welcome.
The proposed new functions I like use cases for are:
lists:groupby
Splits the list into groups using a function as discriminator.
Example:
1> lists:groupby(fun(X) -> X rem 2 end, [1,2,3]).
#{0 => [2], 1 => [1, 3]}
lists:foldlwhile
Like foldl but stops when a certain criteria is met.
lists:uniq
The uniq
function should takes a list and returns the unique elements from that list preserving the order. There is already the usort function which returns unique elements in sorted order.
1> L = [x,y,z,b,a,a,c].
2> lists:uniq(L).
[x,y,z,b,a,c]
3> list:usort(L).
[a,b,c,x,y,z]
lists:transpose
Transposes a list of lists into one list of lists where the first element of each resulting list is taken from the first list and the rest of elements taken from the first element of the following lists.
1> lists:transpose([[1,2,3], [4,5,6]]).
[[1,4],[2,5],[3,6]]