[erlang-questions] How do I elegantly check many conditions?

Hynek Vychodil <>
Fri Mar 20 15:43:30 CET 2009


Pattern match is one of coolest things in Erlang. Note that you can involve
your tag to badmatch error

{my_tag, ok} = {my_tag, my_call(X)}

and custom data too

{my_tag, ok, X} = {my_tag, my_call(X), X}

cool, isn't it?

On Fri, Mar 20, 2009 at 3:34 PM, Paul Fisher <> wrote:

> Hynek Vychodil wrote:
>
>> One of Joe's suggestion: program success case code separated from error
>> handling. You can make it in this way
>>
>> create_user(Email, UserName, Password) ->
>>  try
>>    ok = new_email(Email),
>>    ok = valid_user_name(UserName),
>>    ok = new_user(UserName),
>>    ok = strong_password(Password),
>>    ...
>>    _create_user(Email, UserName, Password)
>>  catch
>>    error:{badmatch, email_in_use} -> do_something();
>>    error:{badmatch, invalid_user_name} -> do_something();
>>    error:{badmatch, user_exists} -> do_something();
>>    error:{badmatch, weak_password} -> do_something();
>>    ...
>>  end.
>>
>
> +1 Bravo!
>
>
> --
> paul
>
>


-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill your
boss.  Be a data hero!
Try Good Data now for free: www.gooddata.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090320/8fc8d0b8/attachment.html>


More information about the erlang-questions mailing list