Skip to content

Instantly share code, notes, and snippets.

@elbrujohalcon
Created October 15, 2014 12:20
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 elbrujohalcon/e1cbe927b28853d7cd3e to your computer and use it in GitHub Desktop.
Save elbrujohalcon/e1cbe927b28853d7cd3e to your computer and use it in GitHub Desktop.
Another partial application
%% I like this way…
1> MultiplePrint = partial(fun lists:zipwith/3, [fun io:format/2]).
#Fun<erl_eval.12.90072148>
2> Salute = partial(MultiplePrint, [["hello ~s!~n", "goodbye ~s!~n"]]).
#Fun<erl_eval.6.90072148>
3> Salute([["@bipthelin"], ["@elbrujohalcon"]]).
hello @bipthelin!
goodbye @elbrujohalcon!
[ok,ok]
%% a little bit more than this way…
1> MultiplePrint = fun(X, Y) -> lists:zipwith(fun io:format/2, X, Y) end.
#Fun<erl_eval.12.90072148>
2> Salute = fun(Y) -> MultiplePrint(["hello ~s!~n", "goodbye ~s!~n"], Y) end.
#Fun<erl_eval.6.90072148>
3> Salute([["@bipthelin"], ["@elbrujohalcon"]]).
hello @bipthelin!
goodbye @elbrujohalcon!
[ok,ok]
%% because if we just want one function, we can do…
1> Salute = partial(fun lists:zipwith/3, [fun io:format/2, ["hello ~s!~n", "goodbye ~s!~n"]]).
#Fun<erl_eval.6.90072148>
2> Salute([["@bipthelin"], ["@elbrujohalcon"]]).
hello @bipthelin!
goodbye @elbrujohalcon!
[ok,ok]
%% instead of…
1> Salute = fun(Y) -> lists:zipwith(fun io:format/2, ["hello ~s!~n", "goodbye ~s!~n"], Y) end.
#Fun<erl_eval.6.90072148>
2> Salute([["@bipthelin"], ["@elbrujohalcon"]]).
hello @bipthelin!
goodbye @elbrujohalcon!
[ok,ok]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment