[erlang-questions] List comprehension question

Rich Neswold <>
Tue May 27 15:25:54 CEST 2014

On Tue, May 27, 2014 at 8:15 AM, Fred Hebert <> wrote:

> On 05/22, Rich Neswold wrote:
> I don't know how many people already use this trick, but I thought it
> might
> > of use to others.
> I used this form before in libraries like bertconf:
> https://github.com/ferd/bertconf/blob/master/src/bertconf_bert_loader.erl#L50-L52
> https://github.com/ferd/bertconf/blob/master/src/bertconf_bert_loader.erl#L93-L94
> My experience has been that it has caused more confusion in readers than
> anything, and I have since then tried to keep that stuff to the strict
> minimum usage possible.
> It's a neat trick, but tricks tend to surprise people.

I agree that tricky and "cute" code should be avoided. The example was
illustrating the technique. My real-world code greatly simplified the
number of lines, so I felt it was a win. Even your first example, if
expanded, would require two case statements and some way to tie the
resulting values back into the list. The comprehension is much cleaner.

Thanks for the feedback and for your examples!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140527/92a281a9/attachment.html>

More information about the erlang-questions mailing list