source: node_modules/ramda/es/filter.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import _arrayReduce from "./internal/_arrayReduce.js";
2import _curry2 from "./internal/_curry2.js";
3import _dispatchable from "./internal/_dispatchable.js";
4import _filter from "./internal/_filter.js";
5import _isObject from "./internal/_isObject.js";
6import _xfilter from "./internal/_xfilter.js";
7import keys from "./keys.js";
8/**
9 * Takes a predicate and a `Filterable`, and returns a new filterable of the
10 * same type containing the members of the given filterable which satisfy the
11 * given predicate. Filterable objects include plain objects or any object
12 * that has a filter method such as `Array`.
13 *
14 * Dispatches to the `filter` method of the second argument, if present.
15 *
16 * Acts as a transducer if a transformer is given in list position.
17 *
18 * @func
19 * @memberOf R
20 * @since v0.1.0
21 * @category List
22 * @category Object
23 * @sig Filterable f => (a -> Boolean) -> f a -> f a
24 * @param {Function} pred
25 * @param {Array} filterable
26 * @return {Array} Filterable
27 * @see R.reject, R.transduce, R.addIndex
28 * @example
29 *
30 * const isEven = n => n % 2 === 0;
31 *
32 * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4]
33 *
34 * R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}
35 */
36
37var filter =
38/*#__PURE__*/
39_curry2(
40/*#__PURE__*/
41_dispatchable(['fantasy-land/filter', 'filter'], _xfilter, function (pred, filterable) {
42 return _isObject(filterable) ? _arrayReduce(function (acc, key) {
43 if (pred(filterable[key])) {
44 acc[key] = filterable[key];
45 }
46
47 return acc;
48 }, {}, keys(filterable)) : // else
49 _filter(pred, filterable);
50}));
51
52export default filter;
Note: See TracBrowser for help on using the repository browser.