List comprehension or lists:foldl/3 ?

Fri Feb 13 09:39:41 CET 2004

> I was just going to write basically the same as Christ wrote.

Well of course if you're going to invoke Him...

> The lists:foreach/2 function is like a map when you
> are only interested in the side-effects. I prefer that
> one in this case. 

Me too. In general, I love list comprehensions, but to make
my intent clear, I only use them when I am interested in the
resulting list.

Comprehensions produce a list.
foreach is for side effects (nothing produced).
foldl is for producing something other than a list (or as well
as a list...)

Dominic Williams.

More information about the erlang-questions mailing list