@aws/pdk
Version:
All documentation is located at: https://aws.github.io/aws-pdk
62 lines (52 loc) • 1.41 kB
JavaScript
var _Set =
/*#__PURE__*/
require("./internal/_Set.js");
var _curry2 =
/*#__PURE__*/
require("./internal/_curry2.js");
var _dispatchable =
/*#__PURE__*/
require("./internal/_dispatchable.js");
var _xuniqBy =
/*#__PURE__*/
require("./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;
}));
module.exports = uniqBy;