Created
September 23, 2015 11:58
-
-
Save raine/0bd2ec53e856a1fe1268 to your computer and use it in GitHub Desktop.
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 { curry, anyPass, toPairs, map, flip, propSatisfies, apply, memoize } = require('ramda'); | |
const strContains = curry((needle, haystack) => haystack.indexOf(needle) >= 0); | |
const objSpecToPreds = memoize((spec) => | |
map(apply(flip(propSatisfies)), toPairs(spec))) | |
const whereAny = curry((spec, obj) => | |
anyPass(objSpecToPreds(spec), obj) | |
); | |
const contract = whereAny({ | |
name: strContains('Alice'), | |
email: strContains('gmail') | |
}); | |
require('treis')(contract)({ name: 'Alice', email: 'foo@example.com' }); | |
require('treis')(contract)({ name: 'bar', email: 'foo@example.com' }); |
Author
raine
commented
Sep 23, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment