Skip to content

Instantly share code, notes, and snippets.

@luizcalaca
Created December 31, 2021 20:19
Show Gist options
  • Save luizcalaca/f6424e5b4f8a568fb767e9705d63d86f to your computer and use it in GitHub Desktop.
Save luizcalaca/f6424e5b4f8a568fb767e9705d63d86f to your computer and use it in GitHub Desktop.
Javascript Currying
//returning many functions result
function sum(a){
return function(b){
return function(c){
return a + b + c
}
}
}
let result = sum(2)(5)(1)
//let's refactor the code above
const result = (a) => {
return (b) => {
return (c) => {
return a + b + c
}
}
}
console.log(result(3)(3)(3))
//let's refactor one more time
const sum = a => b => c => a + b + c
//all returns the same result
console.log(sum(1)(0)(0))
@luizcalaca
Copy link
Author

A biblioteca Ramda possui uma função, R.curry, que recebe uma função e retorna uma versão curried dessa função.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment