Skip to content

Instantly share code, notes, and snippets.

@dmitriid
Last active Aug 4, 2016
Embed
What would you like to do?
start() ->
case chain([ fun some_fun/1
, fun some_fun/2
....
], SomeData) of
{error, _} = E -> E;
{ok, Output} -> Output
end.
some_fun1(Input0) ->
Input = modify_input(Input0),
{ok, Input}.
some_fun2(Input0) ->
try
{ok, weird_stuff(Input0)}
catch
_:Reason -> {error, Reason}
end.
chain([], Output) -> {ok, Output};
chain([F|T], Input) ->
case F(Input) of
{ok, Output} -> chain(T, Output);
{error, _} = E -> E
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment