Last active
September 22, 2017 16:15
-
-
Save dinocarl/adb2b0eb1e14b653ec7db3efd7097551 to your computer and use it in GitHub Desktop.
Uses a curried version of `includes` for a `cond`
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
var fpIncludes = _.curry( function (val, list) { return _.includes(list, val); } ); | |
// or use lodash/fp's includes instead | |
var prop = _.curry( function (val, obj) { return _.get(obj, val); } ); | |
var propOr = _.curry( function (def, val, obj) { return _.get(obj, val, def); } ); | |
var checkForAorD = _.cond([ | |
[fpIncludes('a'), _.constant('matches A')], | |
[fpIncludes('d'), _.constant('matches D')], | |
[_.stubTrue, _.constant('no match')] | |
]); | |
console.log(checkForAorD(['a', 'b', 'c'])); | |
console.log(checkForAorD(['b', 'c', 'd'])); | |
console.log(checkForAorD(['b', 'c'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment