Reputation: 502
I have a function which takes two arguments and returns a function with arity 1:
make_fun(A, B) ->
fun(C) ->
A + B + C
end.
I use the function above to create a function and then apply it to an argument like this:
Fun = make_fun(1,2),
Result = Fun(3).
So that Result = 6
after this.
The question is: Is there a way to do the same thing without storing the function in Fun
?
Something like this would be ideal but doesn't seem to work:
Result = make_fun(1,2)(3).
Upvotes: 2
Views: 105
Reputation: 1626
make_fun(A, B) ->
fun(C) ->
A + B + C
end.
Just put make_fun
in parentheses :
(make_fun(1, 2))(3).
Upvotes: 3