where takes a spec object and a test object and returns true if the test satisfies the spec.
Any property on the spec that is not a function is interpreted as an equality
relation. For example:
var spec = {x: 2};
where(spec, {w: 10, x: 2, y: 300});
where(spec, {x: 1, y: 'moo', z: true});
If the spec has a property mapped to a function, then where evaluates the function, passing in
the test object’s value for the property in question, as well as the whole test object. For example:
var spec = {x: function(val, obj) { return val + obj.y > 10; };
where(spec, {x: 2, y: 7});
where(spec, {x: 3, y: 8});
where is well suited to declarativley expressing constraints for other functions, e.g., filter:
var xs = [{x: 2, y: 1}, {x: 10, y: 2},
{x: 8, y: 3}, {x: 10, y: 4}];
var fxs = filter(where({x: 10}), xs);
R.where = function where(spec, testObj) {
var parsedSpec = R.partition(function(key) {
return typeof spec[key] === "function" ? "fn" : "obj";
}, keys(spec)
);
switch (arguments.length) {
case 0: throw NO_ARGS_EXCEPTION;
case 1:
return function(testObj) {
return satisfiesSpec(spec, parsedSpec, testObj);
};
}
return satisfiesSpec(spec, parsedSpec, testObj);
};