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

Richard O'Keefe ok@REDACTED
Thu May 20 01:37:23 CEST 2010


On May 19, 2010, at 9:05 PM, Ulf Wiger wrote:
a completely useless example for this thread,
because it is an example of someone doing something RIGHT.

> open(F) ->
>  case file:open(F, [read]) of
>     {ok, Fd} -> Fd;
>     {error,_} = Error ->
>         erlang:error(Error)
>  end.

The one possible improvement would be

ok({ok,Good_Result}) -> Good_Result;
ok({error,Reason})   -> erlang:error(Reason).

open(F) ->
     ok(file:open(F, [read])).

possibly extending ok/1 with additional clauses for
additional forms of good and bad outcome.

>



More information about the erlang-questions mailing list