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 slightly more intelligent *Enum.filter/2* Also, I'd say the same syntactic sugar could apply also to *Enum.count/1 *and probably several others. On Sunday, 2 December 2018 18:53:02 UTC, alco wrote: > > 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 <sean.h...@gmail.com > <javascript:>> 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-co...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/a6cb1e15-f32a-4e27-848d-ac8b80f080c0%40googlegroups.com >> >> <https://groups.google.com/d/msgid/elixir-lang-core/a6cb1e15-f32a-4e27-848d-ac8b80f080c0%40googlegroups.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 elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/9e0337b0-4ec0-4329-ad1a-f9f05bca89cb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.