[erlang-questions] chained functions
Reynaldo Baquerizo
reynaldomic@REDACTED
Tue Jan 24 20:31:19 CET 2012
A friend of mine asked:
##
If you have functions that return {ok, Result} | {error, Reason}
how do you chained them? So that you have:
w(x(y(z(...))))
without building a staircasing. Something that would be done in Haskell
with monads.
##
I would probably go for:
x({ok, Value}) ->
NewValue = <do something with Value>,
{ok, NewValue};
x({error, Reason}) ->
{error, Reason}.
in each function
which brings me other question, when do you tag return values?
I tend to only use tagged return values with impure functions, were an
error is more likely due to side effects.
--
Reynaldo
More information about the erlang-questions
mailing list