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

2 Answers2

1

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.

Community
  • 1
  • 1
Raja Rao
  • 5,691
  • 2
  • 28
  • 31
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.

Community
  • 1
  • 1
pellucidcoder
  • 127
  • 3
  • 9