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