[erlang-questions] Style question: accessing record fields in a function clause pattern match?

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Tue Jun 17 16:34:39 CEST 2014

On Tue, Jun 17, 2014 at 4:21 PM, Roger Lipscombe <roger@REDACTED>

> I'm currently refactoring some code, and I've got something like this:
> handle_foo(#state { type = bar, id = Id }) -> whatever;
> handle_foo(#state { type = baz, parent_id = ParentId }) -> whatever.
> ...and I'm wondering whether it's considered bad form to access record
> fields at the same time as matching them in a function clause. I'm
> matching on 'type', and accessing 'id' at the same time, I mean.

Not at all! I think this is the more powerful form. Matching on patterns is
such an integral concept in functional languages, so exploiting it is good.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140617/4dbc0dbd/attachment.htm>

More information about the erlang-questions mailing list