I'm new to Javascript and Typescript and i find it incredibly difficult to understand typescript, in particularly currying functions and arrow syntax.
All this while I've been using the syntax, from Java for functions:
function(param) {
..dosomething..
.
}
and starting javascript lead to arrow syntax functions which i find difficult to understand. In typescript i come across currying where i have examples shown below:
const operationOnTwoNumbers = f => x => y => f(x,y)
const multiply = operationOnTwoNumbers((x,y) => x*y)
const double = multiply(2)
[5,8,3,1,7,6,2].map(double)
I wasn't provided with a lecture of that much detail but according to my slides, it says that multiply is a curried function.
First and foremost, i want to know how do i interpret the operationOnTwoNumbers arrow syntax function. For now, i interpret it as such:
operationOnTwoNumbers is a function that takes in f as an argument, and returns a function that takes x as an argument that returns a function that takes y as an argument that returns a function that does something to x and y.
Am i correct with the interpretation? Would like some feedback on it.
Now for the multiply curried function. My interpretation would be:
multiply is a function that takes operationOnTwoNumbers as a function, that operationOnTwoNumbers take (x,y) as an argument and returns a function that multiplies x and y.
I'm pretty sure my interpretation of these are wrong in a way but i cant seem to understand the syntax. The resource I'm provided with didn't explain much and i tried googling up only to find that I'm getting more confused.
Would really appreciate some help on this, that is for my understanding.
const double = multiply(2)[5,8,3,1,7,6,2].map(double)... because it's trying to access the index of a function... and typescript does not necessarily require any type notation...Uncaught TypeError: Cannot read property 'map' of undefinedin chrome snippets...Exception: TypeError: multiply(...)[2] is undefinedin Firefox scratchpad...