‘Currying’ has the same spelling as Curry that we love.
But ‘currying’ is derived from the name Haskell Brooks Curry who was known as a mathematician and a logician.
Currying is a technique that converting multiple arguments function into a single argument functions sequence.
Like this.
func(a, b, c) -> f(a)(b)(c)
Three arguments function is converted into three functions with single argument each.
f(a) returns value and (b) takes this value as a parameter. (c) also do the same thing. Get’s (b)‘s return value and return.
//non-curried
function plusFunc(a, b, c){
console.log(a + b + c);
}
plusFunc(1, 2, 3); // 6
//curried
function plusFunc(a){
return function(b){
return function(c){
console.log(a + b + c);
}
}
}
plusFunc(1)(2)(4); // 7
Then what are the differences between Curried and Non-curried?
non-curried : Function will be immediately executed even though parameters are not passed. ? Function definition : func(a, b, c) ? Function execution : func(a) ? Execution result : func(a, undefined, undefined)
curried : Execution will be suspended if parameters are not fully passed. ? Function definition : func(a, b, c) ? Function execution : func(a) ? Execution result : func(a) waits for b parameter.
Most of the functions can be implemented without using currying. but you can expect a good effect if you use currying to improve productivity through reusability or readability.
The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it.
‘too’ 文字列を検索する -> /too/ The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it.
大、小文字を構わなく ‘t’ 文字を検索するとき -> /t/-gi The greatest danger for most of us is notthat our aim is too high and we miss it, butthat it is too low and we reach it.
‘d’ から始まる単語及び文字のすべてを検索するとき -> /[d]\w+/-gi The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it.
‘ea’を含む単語を検索するとき -> /[a-z]*ea[a-z]*/-i The greatest danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it
If you see ‘echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list‘, move forward.