Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Case = cases => (
- pred => (
- (typeof cases[pred] !== 'undefined') ? cases[pred]() : cases['_']()
- )
- )
- const count = Case({
- 0: () => 'zero',
- 1: () => 'one',
- _: () => 'many'
- })
- count(0) // 'zero'
- count(1) // 'one'
- count(5) // 'many'
- const cond = Case({
- true: () => 'yes!',
- false: () => 'no :('
- })
- cond(true) // 'yes!'
- cond(false) // 'no :('
- Case({
- 1: () => 'a single item',
- _: () => 'many items'
- })(2) // 'many items'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement