[erlang-questions] chained functions

Richard O'Keefe <>
Fri Jan 27 04:54:56 CET 2012


There's always the possibility of
	eapp(F, E={error,_}) -> E;
	eapp(F, {ok,X}) -> F(X).

Then
	w(x(y(z(...))))
->
	eapp(fun w/1, eapp(fun x/1,
	eapp(fun y/1, eapp(fun z/1, ...))))
and of course this can be turned into a macro:
	-define(eapp(F,X),
	  case ?X of EC1 = {error,_} -> EC1
                   ; OC2 = {ok,OV2}  -> ?X(OV2)
	  end).

Sometimes throwing exceptions is a better choice.




More information about the erlang-questions mailing list