I have been using DateTime and NaiveDateTime alot over the last year and
have found that using the compare function to involves some mental
gymnastics. When using compare you often just want the most recent or
oldest timestamp, or else you want to sort a list of timestamps.
I am proposing four
I love this. My suggestion is to add earliest(date, date) and
earliest(list_of_dates) and the same for latest. We need to add it to Time,
Date, NaiveDateTime and DateTime.
A PR is very appreciated.
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
On Thu, Oct 10,
Oh, I see why you called it sort_earliest, because you also want to allow a
function to be given, in the style of sort_by. I am not a big fan of
sort_earliest though.
What if we add only: DateTime.earliest(list_of_dates) and
DateTime.earliest(list_of_dates, fun)? You can always get the earliest of
If Tyson Buzza don't mind, I would love to write this as my first PR as I
had used Elixir in work for two years and want to do a contribution. : P
On Thu, Oct 10, 2019 at 4:29 PM José Valim
wrote:
> Oh, I see why you called it sort_earliest, because you also want to allow
> a function to be give
I'm in a similar situation to you YongHao. Sorry, but would you mind if I
did it?
To be clear the functionality would be:
DateTime.earliest(enumerable, mapper \\ fn x -> x end)
with a typespec like
@spec earliest(Enum.t(), (any() -> t())) :: list()
right?
On Thursday, October 10, 2019 at 4:4
I think earliest and latest are good because they are descriptive but wondering
if they should be called min and max instead. The advantage of the latter is
they’d be similar to Kernel.min/2 and Enum.min/1,2. I guess a disadvantage is
someone reading `min` could think it returns the minimum allo
Should Date.earliest operate on `Date.t` or `Calendar.date`? That is, should we
allow the following?
iex> Date.earliest([~N[2019-01-01 09:00:00], ~D[2019-01-02])
~D[2019-01-01]
Seems like this could be useful.
--
You received this message because you are subscribed to the Google Group
>
>
To be clear the functionality would be:
>
> DateTime.earliest(enumerable, mapper \\ fn x -> x end)
>
> with a typespec like
>
> @spec earliest(Enum.t(), (any() -> t())) :: list()
>
> right?
>
Correct.
--
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
--
Y
Good catch. It should operate on Calendar.date, as all other functions in
the Date module.
Btw, the reason I prefer earliest/latest is exactly because it has semantic
meaning. It also avoids any confusion from people thinking the regular
min/max work with calendar types (as you said).
On Thu, Oct
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`.
Arg
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 a
Yes, I am with Ben. I have considered adding similar APIs already but I
could not come up with a good proposal. Now I am quite happy with the
current one.
--
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
--
You received this message because you are subscribed
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 an
13 matches
Mail list logo