Created
October 15, 2014 12:20
-
-
Save elbrujohalcon/e1cbe927b28853d7cd3e to your computer and use it in GitHub Desktop.
Another partial application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 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