Which list-map syntax is better and why?

elbrujohalcon
Mon, 23 Mar 2026 16:10:54 +0000
Chat / Discussions

While working on the application of this Elvis rule to a very large project that was recently upgraded from OTP24 to OTP28 I found tons of examples of something like this in it…

[ do:something(X) || X <- …some list… ]

…which is something that can obviously be rewritten as [ do:something(X) || X <:- …some list… ] since we’re not filtering anything in that generator. But (since it doesn’t include any filters and the expression is just the application of a named function), it can also be written as…

lists:map(fun do:something/1, …some list…); or…

lists:foreach(fun do:something/1, …some list…) (if the results are discarded anyway).

So, what do you think fellow Erlangers? Which of the three syntaxes is preferable and why? How would you write such a thing?

10 posts - 7 participants