Skip to content

Instantly share code, notes, and snippets.

@xandkar
Last active November 22, 2017 02:55
Show Gist options
  • Save xandkar/3deed1716ff35848bd1c to your computer and use it in GitHub Desktop.
Save xandkar/3deed1716ff35848bd1c to your computer and use it in GitHub Desktop.
Automatic currying in Erlang
-module(curry).
-export([curry/1]).
curry(F) ->
{arity, Arity} = erlang:fun_info(F, arity),
curry(F, [], Arity).
curry(F, Args, 0) ->
apply(F, lists:reverse(Args));
curry(F, Args, Arity) ->
fun (X) -> curry(F, [X | Args], Arity - 1) end.
@xandkar
Copy link
Author

xandkar commented Apr 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment