[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var _dispatchable =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_dispatchable.js");
|
---|
| 8 |
|
---|
| 9 | var _includesWith =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./internal/_includesWith.js");
|
---|
| 12 |
|
---|
| 13 | var _xuniqWith =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./internal/_xuniqWith.js");
|
---|
| 16 | /**
|
---|
| 17 | * Returns a new list containing only one copy of each element in the original
|
---|
| 18 | * list, based upon the value returned by applying the supplied predicate to
|
---|
| 19 | * two list elements. Prefers the first item if two items compare equal based
|
---|
| 20 | * on the predicate.
|
---|
| 21 | *
|
---|
| 22 | * Acts as a transducer if a transformer is given in list position.
|
---|
| 23 | *
|
---|
| 24 | * @func
|
---|
| 25 | * @memberOf R
|
---|
| 26 | * @since v0.2.0
|
---|
| 27 | * @category List
|
---|
| 28 | * @sig ((a, a) -> Boolean) -> [a] -> [a]
|
---|
| 29 | * @param {Function} pred A predicate used to test whether two items are equal.
|
---|
| 30 | * @param {Array} list The array to consider.
|
---|
| 31 | * @return {Array} The list of unique items.
|
---|
| 32 | * @example
|
---|
| 33 | *
|
---|
| 34 | * const strEq = R.eqBy(String);
|
---|
| 35 | * R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2]
|
---|
| 36 | * R.uniqWith(strEq)([{}, {}]); //=> [{}]
|
---|
| 37 | * R.uniqWith(strEq)([1, '1', 1]); //=> [1]
|
---|
| 38 | * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1']
|
---|
| 39 | */
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | var uniqWith =
|
---|
| 43 | /*#__PURE__*/
|
---|
| 44 | _curry2(
|
---|
| 45 | /*#__PURE__*/
|
---|
| 46 | _dispatchable([], _xuniqWith, function (pred, list) {
|
---|
| 47 | var idx = 0;
|
---|
| 48 | var len = list.length;
|
---|
| 49 | var result = [];
|
---|
| 50 | var item;
|
---|
| 51 |
|
---|
| 52 | while (idx < len) {
|
---|
| 53 | item = list[idx];
|
---|
| 54 |
|
---|
| 55 | if (!_includesWith(pred, item, result)) {
|
---|
| 56 | result[result.length] = item;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | idx += 1;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | return result;
|
---|
| 63 | }));
|
---|
| 64 |
|
---|
| 65 | module.exports = uniqWith; |
---|