Skip to content

Instantly share code, notes, and snippets.

@dinocarl
Last active September 22, 2017 16:15
Show Gist options
  • Save dinocarl/adb2b0eb1e14b653ec7db3efd7097551 to your computer and use it in GitHub Desktop.
Save dinocarl/adb2b0eb1e14b653ec7db3efd7097551 to your computer and use it in GitHub Desktop.
Uses a curried version of `includes` for a `cond`
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