Apologies, I think my previous replies on the topic were
confusing/incomplete.

I proposed Date.earliest/2 meaning that it would return a single date, but
of course, the sort variants are by far more useful. So we would need
Date.sort_earliest/2 or similar but I am bit conflicted because if it is
called sort, it should rather be in Enum as a general purpose function?

Therefore, here are other ideas:

1. We can change Enum.sort/2 and friends so that, besides the sorting
function allowing true/false, it also accepts :gt/:eq/:lt. This means
sorting by earliest is as simple as: Enum.sort(dates, &Date.compare/2). But
we still need a way to do descending sort .

2. Add a new sorting function that when given two elements, must return the
first, instead of true/false today. This means that we could do
Enum.pairsort(dates, &Date.earliest/2) and Enum.pairsort(dates,
&Date.latest/2). "pairsort" is obviously a horrible name, suggestions are
welcome.

Thoughts?

*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D


On Fri, Oct 11, 2019 at 9:33 AM Fernando Tapia Rico <fertap...@gmail.com>
wrote:

> Right.
>
> I meant to return a single element, the "earliest" one. Otherwise I would
> find using a superlative for the function name confusing.
>
> The Decimal library could be another example. It provides a
> Decimal.compare/2 and a more semantic Decimal.min/2 and Decimal.max/2.
>
> On Friday, October 11, 2019 at 9:01:32 AM UTC+2, Tyson Buzza wrote:
>>
>> The earliest function as proposed by Jose above is more like the sort_by
>> function than the min function. It returns a sorted list.
>>
>> On Friday, October 11, 2019 at 2:40:47 PM UTC+8, Fernando Tapia Rico
>> wrote:
>>>
>>> I would drop the `mapper` function, and have a similar interface to
>>> `Enum.min/2`: `DateTime.earliest(list_of_dates, empty_fallback // fn ->
>>> raise(...) end)`.
>>
>> --
> 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 elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/bce11106-9f29-457e-b63f-e6eef0633d74%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/bce11106-9f29-457e-b63f-e6eef0633d74%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KUZ2c54nfWi6oeU%3DbXfs2k_pbOz20Fv4%3DdMNfPUBmPcg%40mail.gmail.com.

Reply via email to