[elixir-core:8385] Re: Enum.sum/2

2018-12-02 Thread Ben Wilson
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

Re: [elixir-core:8384] Enum.sum/2

2018-12-02 Thread Sean Handley
Ok, I can accept that. I'd like to rephrase the advantage: - Write code with clearer intentions. Contrived examples are all quite easy to fathom, but I like seeing *Enum.sum(collection, fun)* where the function decides whether to include the given element in the summation. It's like a

Re: [elixir-core:8382] Enum.sum/2

2018-12-02 Thread Alexei Sholik
The first advantage (write less code) is defeated by adding one more function to the module, thereby increasing the API surface. As for the second one, this code does one pass through the list: Stream.map([1,2,3], & &1*2) |> Enum.sum On Sat, Dec 1, 2018 at 6:19 PM Sean Handley wrote: > Hello,