[erlang-questions] I think I wish I could write case Any of whatever -> _ end.

Robert Raschke rtrlists@REDACTED
Mon May 17 18:09:07 CEST 2010


What's wrong with these? So, your temp var is now called X instead of _ and
you always know what you're looking at.

On Mon, May 17, 2010 at 3:00 PM, Eric Newhuis (personal) <enewhuis@REDACTED
> wrote:

>
> case some_module:some_function(...) of
>        {some, pattern} -> _;
>        {some, other, pattern} -> _;
>        _ -> whatever
> end.
>
>
case X = some_module:some_function(...) of
       {some, pattern} -> X;
       {some, other, pattern} -> X;
       _ -> whatever
end.


case some_module:some_function(...) of
>        {some, pattern} ->
>                {encapsulated, _};
>        {some, other, pattern} ->
>                {another, _, encapsulation}
> end.
>
>
case X = some_module:some_function(...) of
       {some, pattern} ->
               {encapsulated, X};
       {some, other, pattern} ->
               {another, X, encapsulation}
end.


case some_module:some_function(...) of
>        {some, _, pattern} -> % _1
>                case _ of ->  % _2
>                        {some, great, pattern} ->
>                                not_so_bad;
>                        _ -> % _3
>                                {_, Kind, _} = _, % _4, _5, _6
>                                Kind
>                end
> end.
>
>
case some_module:some_function(...) of
       {some, X, pattern} -> % _1
               case X of ->  % _2
                       {some, great, pattern} ->
                               not_so_bad;
                       _ -> % _3
                               {_, Kind, _} = X, % _4, _5, _6
                               Kind
               end
end.


Robby


More information about the erlang-questions mailing list