For currying,if we have a function like this:
function multiply(x, y){
return x * y;
}
multiply(3, 5); // 15
Then its currying version is:
function curriedMultiply(x) {
return function(y) {
return x * y;
}
}
curriedMultiply(3)(5); // 15
For Thunk,if we have a function like this(in Nodejs):
let fs = require('fs')
fs.readFile(fileName,callback)
Then its Thunk version is:
let thunkify = require('thunkify')
let read = thunkify(fs.readFile)
read(fileName)(callback)
Looks like thunk is something to do with currying?They all turn a multi-parameters function into a single-parameters function.And this single-parameters function will return another function which takes the original second parameter and then return the final result.But I notice thunk only takes the callback as the second parameter while for currying there is no limit on the type of the accepeted parameter.
So,is thunk one of the special cases of currying?