To avoid the verbose case statements in Erlang, I sometimes use this function:

ifc(true,  True,  _) -> True;
ifc(false, _, False) -> False;

So instead of writing this:

case proplists:is_defined(empty, Options) of
    true  -> [];
    false -> [some_default]
end

one can write this:

ifc(proplists:is_defined(empty, Options), [], [some_default])

The idea was to mimic the simplicity of C’s (and other languages) ? operator.

Blog comments powered by Disqus