Skip to content

Instantly share code, notes, and snippets.

@raine
Created September 23, 2015 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raine/0bd2ec53e856a1fe1268 to your computer and use it in GitHub Desktop.
Save raine/0bd2ec53e856a1fe1268 to your computer and use it in GitHub Desktop.
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' });
@raine
Copy link
Author

raine commented Sep 23, 2015

λ1 a0: { name: 'Alice', email: 'foo@example.com' }
λ1 => true
λ2 a0: { name: 'bar', email: 'foo@example.com' }
λ2 => false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment