Skip to content

Instantly share code, notes, and snippets.

@joshburgess
Created May 10, 2018 03:48
Show Gist options
  • Save joshburgess/599ef52bea38019dfac88f8d1efd5970 to your computer and use it in GitHub Desktop.
Save joshburgess/599ef52bea38019dfac88f8d1efd5970 to your computer and use it in GitHub Desktop.
Ramda match functions
// 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