Am I misunderstanding, or are the 2nd console.log() calls in your curryMultiply examples incorrect? Shouldn't they be calling curryMultiply() instead of multiply()?
I did it to show that we can also use curryMultiply in the way we normally should have used multiply function. Also, I felt it was kinda obvious that multiply(2, 4) will always return 8 as its just a normal function.
You can call curryMultiply() with two parameters and it will pass them all? I thought it only worked with one parameter (I have a lot more experience with PHP and Go than with Javascript, so I do not know how JS works well enough.)
If it can be used that way then can you please explain that in comments in the code snippet or elsewhere in the article to clarify for others who assume the same as me because that was not at all clear to me when reading?
We check if we already have got enough arguments that are necessary for the function to execute (or arity of that function), as in this case curryMultiply(2, 4). If this condition holds true, we apply (or invoke) the function right away instead of awaiting for another argument like we do for cases like curryMultiply(2)(4)
Am I misunderstanding, or are the 2nd
console.log()
calls in your curryMultiply examples incorrect? Shouldn't they be callingcurryMultiply()
instead ofmultiply()
?You're very right, it was a mistake from my side of not cross checking the code on an editor. Don't know how I missed that.
Thanks a lot, I've updated it now. 😀
Great. However, were you supposed to update the first
console.log()
? Unless I misunderstand, the first one should just callmultiply()
.I did it to show that we can also use
curryMultiply
in the way we normally should have usedmultiply
function. Also, I felt it was kinda obvious thatmultiply(2, 4)
will always return8
as its just a normal function.You can call
curryMultiply()
with two parameters and it will pass them all? I thought it only worked with one parameter (I have a lot more experience with PHP and Go than with Javascript, so I do not know how JS works well enough.)If it can be used that way then can you please explain that in comments in the code snippet or elsewhere in the article to clarify for others who assume the same as me because that was not at all clear to me when reading?
Oops I got caught up in college stuff, apologies!
For now you can fiddle around with this repl to understand how it works! If possible, I'll add a line about this on the blog tomorrow. 🤞 Link to repl
The actual thing is as these two lines of code exist in our custom curry function:
We check if we already have got enough arguments that are necessary for the function to execute (or arity of that function), as in this case
curryMultiply(2, 4)
. If this condition holds true, weapply
(or invoke) the function right away instead of awaiting for another argument like we do for cases likecurryMultiply(2)(4)
which is when the else block of the code executes
Thanks for the detailed reply and REPL.
P.S. RE: "College stuff"; I don't envy you! I did my time years ago and thinking about it still gives me PTSD! :-D