source: node_modules/ramda/src/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.7 KB
Line 
1var _arrayReduce =
2/*#__PURE__*/
3require("./internal/_arrayReduce.js");
4
5var _curry2 =
6/*#__PURE__*/
7require("./internal/_curry2.js");
8
9var _dispatchable =
10/*#__PURE__*/
11require("./internal/_dispatchable.js");
12
13var _filter =
14/*#__PURE__*/
15require("./internal/_filter.js");
16
17var _isObject =
18/*#__PURE__*/
19require("./internal/_isObject.js");
20
21var _xfilter =
22/*#__PURE__*/
23require("./internal/_xfilter.js");
24
25var keys =
26/*#__PURE__*/
27require("./keys.js");
28/**
29 * Takes a predicate and a `Filterable`, and returns a new filterable of the
30 * same type containing the members of the given filterable which satisfy the
31 * given predicate. Filterable objects include plain objects or any object
32 * that has a filter method such as `Array`.
33 *
34 * Dispatches to the `filter` method of the second argument, if present.
35 *
36 * Acts as a transducer if a transformer is given in list position.
37 *
38 * @func
39 * @memberOf R
40 * @since v0.1.0
41 * @category List
42 * @category Object
43 * @sig Filterable f => (a -> Boolean) -> f a -> f a
44 * @param {Function} pred
45 * @param {Array} filterable
46 * @return {Array} Filterable
47 * @see R.reject, R.transduce, R.addIndex
48 * @example
49 *
50 * const isEven = n => n % 2 === 0;
51 *
52 * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4]
53 *
54 * R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4}
55 */
56
57
58var filter =
59/*#__PURE__*/
60_curry2(
61/*#__PURE__*/
62_dispatchable(['fantasy-land/filter', 'filter'], _xfilter, function (pred, filterable) {
63 return _isObject(filterable) ? _arrayReduce(function (acc, key) {
64 if (pred(filterable[key])) {
65 acc[key] = filterable[key];
66 }
67
68 return acc;
69 }, {}, keys(filterable)) : // else
70 _filter(pred, filterable);
71}));
72
73module.exports = filter;
Note: See TracBrowser for help on using the repository browser.