Iterating in Elixir
Lasse Ebert
861

There is a drawback in “don’t mutate objects in ruby.” I am pretty sure, one should not try to [ab]use languages, and ruby is still OO language, hence

def concat_messages(items)
items
.select(&:ok?)
.reduce("") { |acc, item| acc + item.message }
end

The above is in fact to use ruby features. It’s better to mutate the accumulator to reduce an amount of intermediate redundant objects to be created (the latter might even lead to memory leaks, but this is out of scope of this comment):

def concat_messages(items)
items
.select(&:ok?)
.each_with_object("") { |item, acc| acc << item.message }
end
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.