UNPKG

eris-keys

Version:

a JavaScript client library for eris-keys

49 lines (46 loc) 1.42 kB
var _curry2 = require('./internal/_curry2'); var _dispatchable = require('./internal/_dispatchable'); var _filter = require('./internal/_filter'); var _isObject = require('./internal/_isObject'); var _reduce = require('./internal/_reduce'); var _xfilter = require('./internal/_xfilter'); var keys = require('./keys'); /** * Takes a predicate and a "filterable", and returns a new filterable of the * same type containing the members of the given filterable which satisfy the * given predicate. * * Dispatches to the `filter` method of the second argument, if present. * * Acts as a transducer if a transformer is given in list position. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Filterable f => (a -> Boolean) -> f a -> f a * @param {Function} pred * @param {Array} filterable * @return {Array} * @see R.reject, R.transduce, R.addIndex * @example * * var isEven = n => n % 2 === 0; * * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4] * * R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} */ module.exports = _curry2(_dispatchable(['filter'], _xfilter, function(pred, filterable) { return ( _isObject(filterable) ? _reduce(function(acc, key) { if (pred(filterable[key])) { acc[key] = filterable[key]; } return acc; }, {}, keys(filterable)) : // else _filter(pred, filterable) ); }));