[erlang-questions] How to make a short circuit in erlang ?

J K <>
Tue Mar 26 17:18:26 CET 2013

```Hi,
maybe this would work?
http://en.wikipedia.org/wiki/Higher-order_function

or_else([], _) -> false; or_else([F | Fs], X) -> or_else(Fs, X, F(X)). or_else(Fs, X, false) -> or_else(Fs, X); or_else(Fs, _, {false, Y}) -> or_else(Fs, Y); or_else(_, _, R) -> R. or_else([fun erlang:is_integer/1, fun erlang:is_atom/1, fun erlang:is_list/1],3.23).

Johan

>________________________________
> From: 饕餮 <>
>To: erlang-questions <>
>Sent: Tuesday, March 26, 2013 3:31 AM
>Subject: [erlang-questions] How to make a short circuit in erlang ?
>
>
>When in other language.We can use like:
>example(Something){
>    if( Something == false)
>        return;
>    //do something here;
>}
>But in Erlang.I have to write like:
>example(Something) ->
>    if
>        Something == false ->
>            false;
>        true ->
>            %do something here
>    end.
>
>
>That's could make the multiple nested like:
>example(Something) ->
>    if
>        Something == false ->
>            false;
>        true ->
>            if
>                Otherthing == false ->
>                    false
>                true ->
>                    %do something here
>    end.
>
>
>Some code could make 5 or more nested in it.
>Is there any idea to make short circuit to reduce of the nested?
>_______________________________________________
>erlang-questions mailing list
>
>http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130326/50628140/attachment.html>
```