Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
Created August 20, 2021 03:42
Show Gist options
  • Save MeetMartin/983913a4c62ac0243510c5028834c584 to your computer and use it in GitHub Desktop.
Save MeetMartin/983913a4c62ac0243510c5028834c584 to your computer and use it in GitHub Desktop.
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
// 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