1 | "use strict";
|
---|
2 | var __read = (this && this.__read) || function (o, n) {
|
---|
3 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
---|
4 | if (!m) return o;
|
---|
5 | var i = m.call(o), r, ar = [], e;
|
---|
6 | try {
|
---|
7 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
---|
8 | }
|
---|
9 | catch (error) { e = { error: error }; }
|
---|
10 | finally {
|
---|
11 | try {
|
---|
12 | if (r && !r.done && (m = i["return"])) m.call(i);
|
---|
13 | }
|
---|
14 | finally { if (e) throw e.error; }
|
---|
15 | }
|
---|
16 | return ar;
|
---|
17 | };
|
---|
18 | var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
---|
19 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
---|
20 | to[j] = from[i];
|
---|
21 | return to;
|
---|
22 | };
|
---|
23 | exports.__esModule = true;
|
---|
24 | function mergeUnique(key, uniques, getter) {
|
---|
25 | var uniquesSet = new Set(uniques);
|
---|
26 | return function (a, b, k) {
|
---|
27 | return (k === key) && Array.from(__spreadArray(__spreadArray([], __read(a)), __read(b)).map(function (it) { return ({ key: getter(it), value: it }); })
|
---|
28 | .map(function (_a) {
|
---|
29 | var key = _a.key, value = _a.value;
|
---|
30 | return ({ key: (uniquesSet.has(key) ? key : value), value: value });
|
---|
31 | })
|
---|
32 | .reduce(function (m, _a) {
|
---|
33 | var key = _a.key, value = _a.value;
|
---|
34 | m["delete"](key); // This is required to preserve backward compatible order of elements after a merge.
|
---|
35 | return m.set(key, value);
|
---|
36 | }, new Map())
|
---|
37 | .values());
|
---|
38 | };
|
---|
39 | }
|
---|
40 | exports["default"] = mergeUnique;
|
---|
41 | //# sourceMappingURL=unique.js.map |
---|