Skip to content

Instantly share code, notes, and snippets.

@omarkj
Created January 24, 2016 03:07
Show Gist options
  • Save omarkj/4daaae619f116c314bb4 to your computer and use it in GitHub Desktop.
Save omarkj/4daaae619f116c314bb4 to your computer and use it in GitHub Desktop.
Exec
exec([fun fun1/3, fun fun2/4, fun fun3/1], [Arg1, Arg2, Arg2]).

fun1(Arg1, Arg2, Arg3) ->
  P = proplists:get_value(p, Arg1),
  {ok, [P, Arg1, Arg2, Arg3]}.

fun2(P, Arg1, Arg2, Arg3) ->
  do_stuff(P, Arg1, Arg2),
  {ok, [Arg3]}.

fun3(Arg3) -> {ok, thanks}.

Exec is typically implemented something like this

exec([F], Args) ->
  erlang:apply(F, Args);
exec([F|Rest], Args) ->
  case erlang:apply(F, Args) of
	  ok -> exec(Rest, Args);
	  {ok, Args1} -> exec(Rest, Args1);
	  {error, Error} -> {error, Error}
  end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment