53ibhw
Last Updated: February 25, 2016
·
3.525K
· janhenrynystrom
Img 7603

Erlang: Poor mans partial application

-module(partial).

-export([apply/4]).

apply(Module, Name, Arity, Args) when length(Args) < Arity ->
    Left = Arity - length(Args),
    fun(Args1) when length(Args1) < Left ->
            fun(Args2) ->
                apply(Module, Name, Arity, Args2 ++ Args1 ++ Args)
            end;
       (Args1) when length(Args1) > Left ->
            erlang:error(badarg);
       (Args1) ->
            erlang:apply(Module, Name, Args1 ++ Args)
    end;
apply(_, _, Arity, Args) when length(Args) > Arity ->
    erlang:error(badarg);
apply(Module, Name, _, Args) ->
    erlang:apply(Module, Name, Args).
Say Thanks
Respond

1 Response
Add your response

1250
2d8452676ab364e168b927a56b99e472

Hah, nifty. :)

over 1 year ago ·