I don't really agree that it makes the intent clearer. It combines two 
distinct and unrelated activities. One takes the sum of a list, the other 
maps each value in a list to some other value. list |> Enum.map(& &1 * 2) 
|> Enum.sum expresses this perfectly. If you're going for lolspeed and need 
to avoid the second pass then you want a bare recursive function anyway and 
shouldn't even use Enum.

On Saturday, December 1, 2018 at 11:18:58 AM UTC-5, Sean Handley wrote:
>
> Hello,
>
> I'd like to propose *Enum.sum/2*, where the second argument is a function.
>
> This will allow writing
>
> Enum.sum([1, 2, 3], &(&1 * 2))
>
> instead of
>   
> Enum.map([1,2,3], &(&1 * 2)) |> Enum.sum()
>
> The advantages are:
>
> - Write less code.
> - One few iteration across the collection.
>
> I have a branch prepared - 
> https://github.com/elixir-lang/elixir/compare/master...seanhandley:map_with_func
>
> Please let me know your thoughts.
>
> Cheers,
> Sean
>
>

-- 
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/fb7ab97c-3b0d-4772-9525-617cc765414a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to