Hello

for me, the current sort function seems very clear: in the resulting 
enumeration, the predicate will be true for any two adjacent elements.

iex(14)> 1..10 |> Enum.to_list
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

iex(15)> Enum.sort(1..10, &>=/2)
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

iex(16)> 10..1 |> Enum.to_list
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

iex(17)> Enum.sort(10..1, &<=/2)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

I also do not remember of other programming languages having both a "sort" 
and "reverse_sort" functions.

With this in mind, I think we do not need yet another function in an 
already long Enum interface. 

Regards,
Mário


quinta-feira, 17 de Outubro de 2019 às 21:39:42 UTC+1, José Valim escreveu:
>
> I would like to propose a new small function to Enum, called 
> Enum.reverse_sort, that returns sort in the reverse (descending order).
>
> While reversing sorting today is easy to achieve with:
>
> Enum.sort(collection, &>=/2)
>
> I always have a second guess on what the second argument really is. I 
> believe reverse_sort is much clearer in intent:
>
> Enum.reverse_sort(collection)
>
> This is clearer with sort_by too. instead of:
>
> Enum.sort_by(users, & &1.name, &>=/2)
>
> I can write:
>
> Enum.reverse_sort_by(users, & &1.name)
>
> The implementation itself is straight-forward.
>
> What I would like to know is:
>
> 1. Is this a good addition?
> 2. Is the name reasonable? Any other takers?
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/c831e32b-d479-4e20-b2b6-bb2b132b618f%40googlegroups.com.

Reply via email to