Created
May 10, 2018 03:48
-
-
Save joshburgess/599ef52bea38019dfac88f8d1efd5970 to your computer and use it in GitHub Desktop.
Ramda match functions
This file contains hidden or 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
// a simpler version of Ramda's `cond` where you can only match a value against | |
// an object's static key, like how JavaScript's `switch` statement works with `case` | |
// if you need to dynamically match against expression evaluations, use `cond` instead | |
const matchObj = casesObj => fallback => val => casesObj[val] || fallback | |
// or with a syntax more like Ramda's `cond`, taking in an array of pairs instead | |
const matchPairs = compose(matchObj, fromPairs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment