1 | var _arrayReduce =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_arrayReduce.js");
|
---|
4 |
|
---|
5 | var _curry2 =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_curry2.js");
|
---|
8 |
|
---|
9 | var _dispatchable =
|
---|
10 | /*#__PURE__*/
|
---|
11 | require("./internal/_dispatchable.js");
|
---|
12 |
|
---|
13 | var _filter =
|
---|
14 | /*#__PURE__*/
|
---|
15 | require("./internal/_filter.js");
|
---|
16 |
|
---|
17 | var _isObject =
|
---|
18 | /*#__PURE__*/
|
---|
19 | require("./internal/_isObject.js");
|
---|
20 |
|
---|
21 | var _xfilter =
|
---|
22 | /*#__PURE__*/
|
---|
23 | require("./internal/_xfilter.js");
|
---|
24 |
|
---|
25 | var keys =
|
---|
26 | /*#__PURE__*/
|
---|
27 | require("./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 |
|
---|
58 | var 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 |
|
---|
73 | module.exports = filter; |
---|