Created
August 20, 2021 03:42
-
-
Save MeetMartin/983913a4c62ac0243510c5028834c584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const L = require('@7urtle/lambda'); | |
const myCurry = L.curry((a, b) => a + b); | |
const myNary = L.nary(a => b => a + b); | |
// myCurry and myNary can be called | |
// both as curried and n-ary. | |
myCurry(1)(2) === myCurry(1, 2); | |
// => true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// currying: converting a function | |
// that takes multiple arguments | |
// into a sequence of functions | |
// that each takes a single argument | |
// unary - 1 argument, arity: 1 | |
const myUnary = a => a + 1; | |
// binary - 2 arguments, arity: 2 | |
const myBinary = (a, b) => a + b; | |
// n-ary fn to a sequence of unary fn | |
const myCurried = a => b => a + b; | |
myCurried(3)(2); // => 5 | |
const partiallyApplied = myCurried(2); | |
// => b => 2 + b | |
partiallyApplied(5); // => 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment