Skip to content

Instantly share code, notes, and snippets.

@dmitriid
Last active August 4, 2016 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitriid/e2f2cade18bc15176ef1 to your computer and use it in GitHub Desktop.
Save dmitriid/e2f2cade18bc15176ef1 to your computer and use it in GitHub Desktop.
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