Hi!
Recently I found myself several times
in a situation where I needed to sum from an enumerable after
applying a transformation, e.g. sum one field from a list of structs.
There is a temptation to use Enum.map(list, fun) |> Enum.sum() which would be wasteful since it needs to build the
intermediate list.
Enum.reduce(list, 0, &(fun.(&1) + &2) works but it is less
straightforward and less explicit about the intent.
I wondered if Enum.sum(list,
fun) (or Enum.sum_by(list, fun)?) could be a nice addition that would be consistent
with some other Enum functions such as Enum.count/2, Enum.any?/2. What do you think?