FWIW We have an earliest_date and latest_date helper in almost every Elixir 
app we've built. The Enum.sort solution requires requires too many leaps to 
be at a glance readable if it's been a bit since you used DateTime.compare.

Definitely a fan of including this.

On Thursday, October 10, 2019 at 5:31:29 AM UTC-4, Wiebe-Marten Wijnja 
wrote:
>
> Playing devil's advocate here for a minute: The wanted functionality could 
> also be reached using
>
> Enum.sort(enumerable, &(DateTime.compare(&1, &2) in [:lt, :eq]))
>
> for `DateTime.earliest`
>
> and similarly:
>
> Enum.sort(enumerable, &(DateTime.compare(&1, &2) in [:eq, :gt]))
>
> for `DateTime.latest`.
>
> Arguably this does require some mental gymnastics. However, is that enough 
> reason to introduce eight new functions? (two for each of Time, Date, 
> NaiveDateTime and DateTime)?
>
> Maybe these mental gymnastics are not 'too bad'?
> Or maybe we do want to make it somewhat easier for the users, but there 
> exists a simpler, more fundamental alternative we could implement, which 
> could then be re-usable in multiple contexts?
>
> For instance, if we only had `DateTime.earliest(dt1, dt2)` then we could 
> write:
>
> Enum.sort(enumerable, &(DateTime.earliest(&1, &2) == &1))
> for the first case, and 
> Enum.sort(enumerable, &(DateTime.earliest(&1, &2) == &2))
> for the second.
>
> ~Qqwy/Marten
>

-- 
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/bd408b05-f8f5-4ebe-b466-f5af2cbd66d9%40googlegroups.com.

Reply via email to