Skip to content

Instantly share code, notes, and snippets.

@dralletje
Created August 29, 2015 16:45
Show Gist options
  • Save dralletje/9be154509d2e14d7ecb4 to your computer and use it in GitHub Desktop.
Save dralletje/9be154509d2e14d7ecb4 to your computer and use it in GitHub Desktop.
import objectassign from 'object-assign'
Object.assign = objectassign
function add(...xs) {
const x = xs.reduce((a,b) => a+b)
return Object.assign((...ys) => add(x, ...ys), { valueOf: () => x })
}
function test(a, b) {
console.log(a == b ? 'OK' : a + ' != ' + b)
}
test(add(1, 2), 3);
test(add(3)(4)(), 7);
test(add(3)(4)(5), 12);
const three = add(3);
const four = add(4);
test(three, 3);
test(four, 4);
test(three(5), 8);
test(three(6), 9);
test(three(four), 7);
test(three(four)(three(four)), 14);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment