Last active
February 12, 2018 10:56
-
-
Save davidbarral/9b99cff5069840469afcf07fd88d52f7 to your computer and use it in GitHub Desktop.
Curry: TDD partial application
This file contains 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 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