3

I recall somewhere seeing a function with two parenthesis brackets ()() like:

function add_numbers(number1)(number2)

What do you call such a function and what’s its usage?

Thank you in advance and will be sure to vote up/accept answer

0

2 Answers 2

2

It is called function currying. The first bracket returns another function(lets call it: "myCustomFunc"). The 2nd bracket actually passes the 2nd value (number2) to the myCustomFunc.

Sign up to request clarification or add additional context in comments.

Comments

0

Going off of this answer, the add_numbers function takes one argument (number1) and returns a function, which is then called with argument number2.

2 Comments

My question? I don't understand
Basically, function 1 takes one argument, and returns a function, let's call it function 2, which takes another argument and returns a result.