1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import _Set from "./internal/_Set.js";
- import _curry2 from "./internal/_curry2.js";
- import _dispatchable from "./internal/_dispatchable.js";
- import _xuniqBy from "./internal/_xuniqBy.js";
- /**
- * Returns a new list containing only one copy of each element in the original
- * list, based upon the value returned by applying the supplied function to
- * each list element. Prefers the first item if the supplied function produces
- * the same value on two items. [`R.equals`](#equals) is used for comparison.
- *
- * Acts as a transducer if a transformer is given in list position.
- *
- * @func
- * @memberOf R
- * @since v0.16.0
- * @category List
- * @sig (a -> b) -> [a] -> [a]
- * @param {Function} fn A function used to produce a value to use during comparisons.
- * @param {Array} list The array to consider.
- * @return {Array} The list of unique items.
- * @example
- *
- * R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10]
- */
- var uniqBy =
- /*#__PURE__*/
- _curry2(
- /*#__PURE__*/
- _dispatchable([], _xuniqBy, function (fn, list) {
- var set = new _Set();
- var result = [];
- var idx = 0;
- var appliedItem, item;
- while (idx < list.length) {
- item = list[idx];
- appliedItem = fn(item);
- if (set.add(appliedItem)) {
- result.push(item);
- }
- idx += 1;
- }
- return result;
- }));
- export default uniqBy;
|