Hi If this function were to exist I think we would need to call it `sum_map/2`, as the combination of `sum` and `map`. Previously we had `Enum.filter_map/2`, though it was deprecated in favour of `Enum.filter/2` and `Enum.map/2`. The trend is that we are removing these combined Enum functions rather than adding them, so it seems unlikely that we would add this new kind of `sum` if we continued this debate.
A good point from Ben, the polymorphic nature of Enum and the Enumerable protocol means it is slower than using the List module or writing recursive functions, so for this kind of performance tuning the Enum module is probably not the right place to start. Cheers, Louis On Mon, 3 Dec 2018 at 02:19 Ben Wilson <benwilson...@gmail.com> wrote: > 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 > <https://groups.google.com/d/msgid/elixir-lang-core/fb7ab97c-3b0d-4772-9525-617cc765414a%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/CABu8xFBEb-%3DuO4Ft3q1SVnpedyByOJKZ_w9CYRE2tawQhVY%3DHw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.