I strongly prefer rolling this all into enum. As you say, José, turtles all
the way down!

This is a brainstorm for naming options, not a proposal. I'm not attached
to any of these.

Pairsort options:

- order(..., ordering \\ :asc)
- order_asc, order_desc
- compare

optionally, a variant on sort:

sort_elements



or, translate elements to other things that can be sorted, like this:

rank(dates, ordering \\ :asc)

That could take

[date1, date2]

and return rankings that can be sorted, like this:

[2, 1]

That could be as easy as converting to unix date.

Do any of these ideas help?

-bt

On Sat, Oct 12, 2019 at 7:58 AM José Valim <jose.va...@plataformatec.com.br>
wrote:

> 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
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KUZ2c54nfWi6oeU%3DbXfs2k_pbOz20Fv4%3DdMNfPUBmPcg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Regards,
Bruce Tate
CEO

<https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97>

Groxio, LLC.
512.799.9366
br...@grox.io
grox.io

-- 
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/CAFXvW-5tHY%3DPRq3vMe%3DBiuYEuPQDDdFBOCNjhc5i1WkHg-RhUA%40mail.gmail.com.

Reply via email to