Skip to content

Instantly share code, notes, and snippets.

@davidbarral
Last active February 12, 2018 10:56
Show Gist options
  • Save davidbarral/9b99cff5069840469afcf07fd88d52f7 to your computer and use it in GitHub Desktop.
Save davidbarral/9b99cff5069840469afcf07fd88d52f7 to your computer and use it in GitHub Desktop.
Curry: TDD partial application
const expect = x => ({
toBe: y => {
if (x !== y) {
throw new Error(`expected ${x} to be ${y}`);
}
}
});
const sum4 = curry((a, b, c, d) => a + b + c + d);
expect(sum4()(1, 2, 3, 4)).toBe(10);
expect(sum4(1)(2, 3, 4)).toBe(10);
expect(sum4(1, 2)(3, 4)).toBe(10);
expect(sum4(1, 2, 3)(4)).toBe(10);
expect(sum4(1, 2, 3, 4)).toBe(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment