Created
March 20, 2017 07:45
-
-
Save pvpshoot/6526bd3279e837c0cf43a4c42b4fd067 to your computer and use it in GitHub Desktop.
fp-switch, pattern matching
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 patternMatch = (o, cond, or) => { | |
if (typeof o[cond] !== 'function') { | |
return or || null; | |
} | |
return o[cond](); | |
} | |
const TEST = { | |
lol(){ return: 'lol' }, | |
kek(){ return: 'kek' }, | |
cheburek(){ return: 'cheburek' }, | |
} | |
const DEFAULT = 'something default'; | |
console.log(patternMatch(TEST, 'kek', DEFAULT)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment