Btw, if you don't have time to send a PR, please open up an issue and
someone will certainly grab it. :)



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

On Thu, Aug 11, 2016 at 8:25 PM, José Valim <[email protected]
> wrote:

> I am +1 for the function based function because we can argue that the
> default function raises Enum.EmptyError. So we keep backwards compatibility
> and get a feature out of it. :)
>
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
> On Thu, Aug 11, 2016 at 7:59 PM, Myron Marston <[email protected]>
> wrote:
>
>> When using Enum’s min/max/min_max functions, I frequently have to provide
>> special case logic to deal with an empty collection, such as this:
>>
>> def date_range_from(all_time_slices) do
>>   case all_time_slices do
>>     [] -> {nil, nil}
>>     [_ | _] -> Enum.min_max(all_time_slices)
>>   endend
>>
>> It would be nice if there was a 2-arity version of these functions that
>> you could pass to determine what to do with an empty collection. For this
>> case, I’m imagining:
>>
>> def date_range_from(all_time_slices) do
>>   Enum.min_max(all_time_slices, {nil, nil})end
>>
>> This aligns with functions like Map.get/3 that allow you to pass a
>> default. Alternately, I could see an argument for requiring the 2nd
>> argument to be a function:
>>
>> def date_range_from(all_time_slices) do
>>   Enum.min_max(all_time_slices, fn -> {nil, nil} end)end
>>
>> Then the 1-arity version of these functions could just call the 2-arity
>> version with a function that raises an Enum.EmptyError. That said, I
>> think I prefer the version that allows you to pass a default return value
>> w/ no need to wrap it in a function.
>>
>> Thoughts?
>> Myron
>> ​
>>
>> --
>> 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/ms
>> gid/elixir-lang-core/CADUxQmvSuQrudQ07U9Tvbwek-KRL_c9r9eW_P-
>> RQ%2BbGM07do4A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/elixir-lang-core/CADUxQmvSuQrudQ07U9Tvbwek-KRL_c9r9eW_P-RQ%2BbGM07do4A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/CAGnRm4%2BJVUyi8%2BFxC%3Ds8sx%2BBy73bv-OuS%2BLEsY9Y7c-5y5dZ6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to