@softwareventures/array 7.0.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/index.d.ts +6 -0
- package/index.js +193 -211
- package/index.js.map +1 -1
- package/index.test.d.ts +1 -0
- package/index.test.js +336 -0
- package/index.test.js.map +1 -0
- package/package.json +30 -30
- package/.husky/common.sh +0 -8
- package/.husky/pre-commit +0 -5
- package/.prettierignore +0 -6
package/index.js
CHANGED
|
@@ -1,26 +1,195 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
3
|
+
exports.map = exports.isArray = exports.copy = void 0;
|
|
4
|
+
exports.isArrayLike = isArrayLike;
|
|
5
|
+
exports.coerce = coerce;
|
|
6
|
+
exports.first = first;
|
|
7
|
+
exports.tail = tail;
|
|
8
|
+
exports.push = push;
|
|
9
|
+
exports.pushFn = pushFn;
|
|
10
|
+
exports.unshift = unshift;
|
|
11
|
+
exports.unshiftFn = unshiftFn;
|
|
12
|
+
exports.initial = initial;
|
|
13
|
+
exports.last = last;
|
|
14
|
+
exports.only = only;
|
|
15
|
+
exports.empty = empty;
|
|
16
|
+
exports.notEmpty = notEmpty;
|
|
17
|
+
exports.reverse = reverse;
|
|
18
|
+
exports.slice = slice;
|
|
19
|
+
exports.sliceFn = sliceFn;
|
|
20
|
+
exports.take = take;
|
|
21
|
+
exports.takeFn = takeFn;
|
|
22
|
+
exports.drop = drop;
|
|
23
|
+
exports.dropFn = dropFn;
|
|
24
|
+
exports.takeWhile = takeWhile;
|
|
25
|
+
exports.takeWhileFn = takeWhileFn;
|
|
26
|
+
exports.takeUntil = takeUntil;
|
|
27
|
+
exports.takeUntilFn = takeUntilFn;
|
|
28
|
+
exports.dropWhile = dropWhile;
|
|
29
|
+
exports.dropWhileFn = dropWhileFn;
|
|
30
|
+
exports.dropUntil = dropUntil;
|
|
31
|
+
exports.dropUntilFn = dropUntilFn;
|
|
32
|
+
exports.equal = equal;
|
|
33
|
+
exports.equalFn = equalFn;
|
|
34
|
+
exports.notEqual = notEqual;
|
|
35
|
+
exports.notEqualFn = notEqualFn;
|
|
36
|
+
exports.prefixMatch = prefixMatch;
|
|
37
|
+
exports.prefixMatchFn = prefixMatchFn;
|
|
38
|
+
exports.mapFn = mapFn;
|
|
39
|
+
exports.filter = filter;
|
|
40
|
+
exports.filterFn = filterFn;
|
|
41
|
+
exports.exclude = exclude;
|
|
42
|
+
exports.excludeFn = excludeFn;
|
|
43
|
+
exports.excludeNull = excludeNull;
|
|
44
|
+
exports.excludeFirst = excludeFirst;
|
|
45
|
+
exports.excludeFirstFn = excludeFirstFn;
|
|
46
|
+
exports.remove = remove;
|
|
47
|
+
exports.removeFn = removeFn;
|
|
48
|
+
exports.removeFirst = removeFirst;
|
|
49
|
+
exports.removeFirstFn = removeFirstFn;
|
|
50
|
+
exports.fold = fold;
|
|
51
|
+
exports.foldFn = foldFn;
|
|
52
|
+
exports.fold1 = fold1;
|
|
53
|
+
exports.fold1Fn = fold1Fn;
|
|
54
|
+
exports.foldRight = foldRight;
|
|
55
|
+
exports.foldRightFn = foldRightFn;
|
|
56
|
+
exports.foldRight1 = foldRight1;
|
|
57
|
+
exports.foldRight1Fn = foldRight1Fn;
|
|
58
|
+
exports.foldMap = foldMap;
|
|
59
|
+
exports.foldMapFn = foldMapFn;
|
|
60
|
+
exports.foldMapRight = foldMapRight;
|
|
61
|
+
exports.foldMapRightFn = foldMapRightFn;
|
|
62
|
+
exports.contains = contains;
|
|
63
|
+
exports.containsFn = containsFn;
|
|
64
|
+
exports.indexOf = indexOf;
|
|
65
|
+
exports.indexOfFn = indexOfFn;
|
|
66
|
+
exports.lastIndexOf = lastIndexOf;
|
|
67
|
+
exports.lastIndexOfFn = lastIndexOfFn;
|
|
68
|
+
exports.findIndex = findIndex;
|
|
69
|
+
exports.findIndexFn = findIndexFn;
|
|
70
|
+
exports.findLastIndex = findLastIndex;
|
|
71
|
+
exports.findLastIndexFn = findLastIndexFn;
|
|
72
|
+
exports.find = find;
|
|
73
|
+
exports.findFn = findFn;
|
|
74
|
+
exports.findLast = findLast;
|
|
75
|
+
exports.findLastFn = findLastFn;
|
|
76
|
+
exports.maximum = maximum;
|
|
77
|
+
exports.maximumFn = maximumFn;
|
|
78
|
+
exports.maximumBy = maximumBy;
|
|
79
|
+
exports.maximumByFn = maximumByFn;
|
|
80
|
+
exports.minimum = minimum;
|
|
81
|
+
exports.minimumFn = minimumFn;
|
|
82
|
+
exports.minimumBy = minimumBy;
|
|
83
|
+
exports.minimumByFn = minimumByFn;
|
|
84
|
+
exports.sum = sum;
|
|
85
|
+
exports.product = product;
|
|
86
|
+
exports.average = average;
|
|
87
|
+
exports.and = and;
|
|
88
|
+
exports.or = or;
|
|
89
|
+
exports.any = any;
|
|
90
|
+
exports.anyFn = anyFn;
|
|
91
|
+
exports.all = all;
|
|
92
|
+
exports.allFn = allFn;
|
|
93
|
+
exports.concat = concat;
|
|
94
|
+
exports.prepend = prepend;
|
|
95
|
+
exports.append = append;
|
|
96
|
+
exports.concatMap = concatMap;
|
|
97
|
+
exports.concatMapFn = concatMapFn;
|
|
98
|
+
exports.noneNull = noneNull;
|
|
99
|
+
exports.scan = scan;
|
|
100
|
+
exports.scanFn = scanFn;
|
|
101
|
+
exports.scan1 = scan1;
|
|
102
|
+
exports.scan1Fn = scan1Fn;
|
|
103
|
+
exports.scanRight = scanRight;
|
|
104
|
+
exports.scanRightFn = scanRightFn;
|
|
105
|
+
exports.scanRight1 = scanRight1;
|
|
106
|
+
exports.scanRight1Fn = scanRight1Fn;
|
|
107
|
+
exports.split = split;
|
|
108
|
+
exports.splitFn = splitFn;
|
|
109
|
+
exports.partition = partition;
|
|
110
|
+
exports.partitionFn = partitionFn;
|
|
111
|
+
exports.partitionWhile = partitionWhile;
|
|
112
|
+
exports.partitionWhileFn = partitionWhileFn;
|
|
113
|
+
exports.partitionUntil = partitionUntil;
|
|
114
|
+
exports.partitionUntilFn = partitionUntilFn;
|
|
115
|
+
exports.zip = zip;
|
|
116
|
+
exports.zipFn = zipFn;
|
|
117
|
+
exports.keyBy = keyBy;
|
|
118
|
+
exports.keyByFn = keyByFn;
|
|
119
|
+
exports.keyFirstBy = keyFirstBy;
|
|
120
|
+
exports.keyFirstByFn = keyFirstByFn;
|
|
121
|
+
exports.keyLastBy = keyLastBy;
|
|
122
|
+
exports.keyLastByFn = keyLastByFn;
|
|
123
|
+
exports.mapKeyBy = mapKeyBy;
|
|
124
|
+
exports.mapKeyByFn = mapKeyByFn;
|
|
125
|
+
exports.mapKeyFirstBy = mapKeyFirstBy;
|
|
126
|
+
exports.mapKeyFirstByFn = mapKeyFirstByFn;
|
|
127
|
+
exports.mapKeyLastBy = mapKeyLastBy;
|
|
128
|
+
exports.mapKeyLastByFn = mapKeyLastByFn;
|
|
129
|
+
exports.group = group;
|
|
130
|
+
exports.groupFn = groupFn;
|
|
131
|
+
exports.groupByIdentity = groupByIdentity;
|
|
132
|
+
exports.groupByIdentityFn = groupByIdentityFn;
|
|
133
|
+
exports.groupByEquality = groupByEquality;
|
|
134
|
+
exports.groupByEqualityFn = groupByEqualityFn;
|
|
135
|
+
exports.groupByOrder = groupByOrder;
|
|
136
|
+
exports.groupByOrderFn = groupByOrderFn;
|
|
137
|
+
exports.groupByHash = groupByHash;
|
|
138
|
+
exports.groupByHashFn = groupByHashFn;
|
|
139
|
+
exports.groupByEqualityWithHash = groupByEqualityWithHash;
|
|
140
|
+
exports.groupByEqualityWithHashFn = groupByEqualityWithHashFn;
|
|
141
|
+
exports.groupByOrderWithHash = groupByOrderWithHash;
|
|
142
|
+
exports.groupByOrderWithHashFn = groupByOrderWithHashFn;
|
|
143
|
+
exports.groupAdjacent = groupAdjacent;
|
|
144
|
+
exports.groupAdjacentFn = groupAdjacentFn;
|
|
145
|
+
exports.groupAdjacentByIdentity = groupAdjacentByIdentity;
|
|
146
|
+
exports.groupAdjacentByIdentityFn = groupAdjacentByIdentityFn;
|
|
147
|
+
exports.groupAdjacentByEquality = groupAdjacentByEquality;
|
|
148
|
+
exports.groupAdjacentByEqualityFn = groupAdjacentByEqualityFn;
|
|
149
|
+
exports.groupAdjacentByOrder = groupAdjacentByOrder;
|
|
150
|
+
exports.groupAdjacentByOrderFn = groupAdjacentByOrderFn;
|
|
151
|
+
exports.groupAdjacentByHash = groupAdjacentByHash;
|
|
152
|
+
exports.groupAdjacentByHashFn = groupAdjacentByHashFn;
|
|
153
|
+
exports.unique = unique;
|
|
154
|
+
exports.uniqueFn = uniqueFn;
|
|
155
|
+
exports.uniqueByIdentity = uniqueByIdentity;
|
|
156
|
+
exports.uniqueByEquality = uniqueByEquality;
|
|
157
|
+
exports.uniqueByEqualityFn = uniqueByEqualityFn;
|
|
158
|
+
exports.uniqueByOrder = uniqueByOrder;
|
|
159
|
+
exports.uniqueByOrderFn = uniqueByOrderFn;
|
|
160
|
+
exports.uniqueByHash = uniqueByHash;
|
|
161
|
+
exports.uniqueByHashFn = uniqueByHashFn;
|
|
162
|
+
exports.uniqueByEqualityWithHash = uniqueByEqualityWithHash;
|
|
163
|
+
exports.uniqueByEqualityWithHashFn = uniqueByEqualityWithHashFn;
|
|
164
|
+
exports.uniqueByOrderWithHash = uniqueByOrderWithHash;
|
|
165
|
+
exports.uniqueByOrderWithHashFn = uniqueByOrderWithHashFn;
|
|
166
|
+
exports.uniqueAdjacent = uniqueAdjacent;
|
|
167
|
+
exports.uniqueAdjacentFn = uniqueAdjacentFn;
|
|
168
|
+
exports.uniqueAdjacentByIdentity = uniqueAdjacentByIdentity;
|
|
169
|
+
exports.uniqueAdjacentByIdentityFn = uniqueAdjacentByIdentityFn;
|
|
170
|
+
exports.uniqueAdjacentByEquality = uniqueAdjacentByEquality;
|
|
171
|
+
exports.uniqueAdjacentByEqualityFn = uniqueAdjacentByEqualityFn;
|
|
172
|
+
exports.uniqueAdjacentByOrder = uniqueAdjacentByOrder;
|
|
173
|
+
exports.uniqueAdjacentByOrderFn = uniqueAdjacentByOrderFn;
|
|
174
|
+
exports.uniqueAdjacentByHash = uniqueAdjacentByHash;
|
|
175
|
+
exports.uniqueAdjacentByHashFn = uniqueAdjacentByHashFn;
|
|
176
|
+
exports.sort = sort;
|
|
177
|
+
exports.sortFn = sortFn;
|
|
178
|
+
exports.sortBy = sortBy;
|
|
179
|
+
exports.sortByFn = sortByFn;
|
|
180
|
+
exports.sortByDescending = sortByDescending;
|
|
181
|
+
exports.sortByDescendingFn = sortByDescendingFn;
|
|
182
|
+
exports.forEach = forEach;
|
|
183
|
+
exports.forEachFn = forEachFn;
|
|
7
184
|
const nullable_1 = require("@softwareventures/nullable");
|
|
8
185
|
const ordered_1 = require("@softwareventures/ordered");
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
10
186
|
const nativeSlice = Array.prototype.slice;
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
12
187
|
const nativeReverse = Array.prototype.reverse;
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
14
188
|
const nativeConcat = Array.prototype.concat;
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
16
189
|
const nativeFilter = Array.prototype.filter;
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
18
190
|
const nativeReduce = Array.prototype.reduce;
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
20
191
|
const nativeReduceRight = Array.prototype.reduceRight;
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
22
192
|
const nativeIndexOf = Array.prototype.indexOf;
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
24
193
|
const nativeFindIndex = Array.prototype.findIndex;
|
|
25
194
|
/** @internal This implementation is for internal use only, the exported declaration is above */
|
|
26
195
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -30,92 +199,71 @@ exports.copy = Array.from;
|
|
|
30
199
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
200
|
// @ts-ignore duplicate identifier: This is the actual implementation, the exported declaration is above.
|
|
32
201
|
exports.isArray = Array.isArray;
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
34
202
|
function isArrayLike(value) {
|
|
35
203
|
return (typeof value === "object" &&
|
|
36
204
|
value != null &&
|
|
37
205
|
"length" in value &&
|
|
38
206
|
typeof value.length === "number");
|
|
39
207
|
}
|
|
40
|
-
exports.isArrayLike = isArrayLike;
|
|
41
208
|
function coerce(array) {
|
|
42
209
|
return (0, exports.isArray)(array) ? array : (0, exports.copy)(array);
|
|
43
210
|
}
|
|
44
|
-
exports.coerce = coerce;
|
|
45
211
|
function first(array) {
|
|
46
212
|
return array.length === 0 ? null : array[0];
|
|
47
213
|
}
|
|
48
|
-
exports.first = first;
|
|
49
214
|
function tail(array) {
|
|
50
215
|
return nativeSlice.call(array, 1);
|
|
51
216
|
}
|
|
52
|
-
exports.tail = tail;
|
|
53
217
|
function push(array, value) {
|
|
54
218
|
return [...coerce(array), value];
|
|
55
219
|
}
|
|
56
|
-
exports.push = push;
|
|
57
220
|
function pushFn(value) {
|
|
58
221
|
return array => push(array, value);
|
|
59
222
|
}
|
|
60
|
-
exports.pushFn = pushFn;
|
|
61
223
|
function unshift(array, value) {
|
|
62
224
|
return [value, ...coerce(array)];
|
|
63
225
|
}
|
|
64
|
-
exports.unshift = unshift;
|
|
65
226
|
function unshiftFn(value) {
|
|
66
227
|
return array => unshift(array, value);
|
|
67
228
|
}
|
|
68
|
-
exports.unshiftFn = unshiftFn;
|
|
69
229
|
function initial(array) {
|
|
70
230
|
return array.length === 0 ? [] : nativeSlice.call(array, 0, array.length - 1);
|
|
71
231
|
}
|
|
72
|
-
exports.initial = initial;
|
|
73
232
|
function last(array) {
|
|
74
233
|
return array.length === 0 ? null : array[array.length - 1];
|
|
75
234
|
}
|
|
76
|
-
exports.last = last;
|
|
77
235
|
/** If the array contains exactly one element, returns that element.
|
|
78
236
|
* Otherwise, returns null. */
|
|
79
237
|
function only(array) {
|
|
80
238
|
return array.length === 1 ? array[0] : null;
|
|
81
239
|
}
|
|
82
|
-
exports.only = only;
|
|
83
240
|
function empty(array) {
|
|
84
241
|
return array.length === 0;
|
|
85
242
|
}
|
|
86
|
-
exports.empty = empty;
|
|
87
243
|
function notEmpty(array) {
|
|
88
244
|
return array.length > 0;
|
|
89
245
|
}
|
|
90
|
-
exports.notEmpty = notEmpty;
|
|
91
246
|
function reverse(array) {
|
|
92
247
|
return nativeReverse.call((0, exports.copy)(array));
|
|
93
248
|
}
|
|
94
|
-
exports.reverse = reverse;
|
|
95
249
|
function slice(array, start, end) {
|
|
96
250
|
return nativeSlice.call(array, start, end);
|
|
97
251
|
}
|
|
98
|
-
exports.slice = slice;
|
|
99
252
|
function sliceFn(start, end) {
|
|
100
253
|
return array => nativeSlice.call(array, start, end);
|
|
101
254
|
}
|
|
102
|
-
exports.sliceFn = sliceFn;
|
|
103
255
|
function take(array, count) {
|
|
104
256
|
return nativeSlice.call(array, 0, count);
|
|
105
257
|
}
|
|
106
|
-
exports.take = take;
|
|
107
258
|
function takeFn(count) {
|
|
108
259
|
return array => nativeSlice.call(array, 0, count);
|
|
109
260
|
}
|
|
110
|
-
exports.takeFn = takeFn;
|
|
111
261
|
function drop(array, count) {
|
|
112
262
|
return nativeSlice.call(array, count);
|
|
113
263
|
}
|
|
114
|
-
exports.drop = drop;
|
|
115
264
|
function dropFn(count) {
|
|
116
265
|
return array => nativeSlice.call(array, count);
|
|
117
266
|
}
|
|
118
|
-
exports.dropFn = dropFn;
|
|
119
267
|
function takeWhile(array, predicate) {
|
|
120
268
|
let i = 0;
|
|
121
269
|
while (i < array.length && predicate(array[i], i)) {
|
|
@@ -123,19 +271,15 @@ function takeWhile(array, predicate) {
|
|
|
123
271
|
}
|
|
124
272
|
return take(array, i);
|
|
125
273
|
}
|
|
126
|
-
exports.takeWhile = takeWhile;
|
|
127
274
|
function takeWhileFn(predicate) {
|
|
128
275
|
return array => takeWhile(array, predicate);
|
|
129
276
|
}
|
|
130
|
-
exports.takeWhileFn = takeWhileFn;
|
|
131
277
|
function takeUntil(array, predicate) {
|
|
132
278
|
return takeWhile(array, (element, index) => !predicate(element, index));
|
|
133
279
|
}
|
|
134
|
-
exports.takeUntil = takeUntil;
|
|
135
280
|
function takeUntilFn(predicate) {
|
|
136
281
|
return array => takeUntil(array, predicate);
|
|
137
282
|
}
|
|
138
|
-
exports.takeUntilFn = takeUntilFn;
|
|
139
283
|
function dropWhile(array, predicate) {
|
|
140
284
|
let i = 0;
|
|
141
285
|
while (i < array.length && predicate(array[i], i)) {
|
|
@@ -143,19 +287,15 @@ function dropWhile(array, predicate) {
|
|
|
143
287
|
}
|
|
144
288
|
return drop(array, i);
|
|
145
289
|
}
|
|
146
|
-
exports.dropWhile = dropWhile;
|
|
147
290
|
function dropWhileFn(predicate) {
|
|
148
291
|
return array => dropWhile(array, predicate);
|
|
149
292
|
}
|
|
150
|
-
exports.dropWhileFn = dropWhileFn;
|
|
151
293
|
function dropUntil(array, predicate) {
|
|
152
294
|
return dropWhile(array, (element, index) => !predicate(element, index));
|
|
153
295
|
}
|
|
154
|
-
exports.dropUntil = dropUntil;
|
|
155
296
|
function dropUntilFn(predicate) {
|
|
156
297
|
return array => dropWhile(array, predicate);
|
|
157
298
|
}
|
|
158
|
-
exports.dropUntilFn = dropUntilFn;
|
|
159
299
|
function equal(a, b, elementsEqual = ordered_1.equal) {
|
|
160
300
|
if (a.length !== b.length) {
|
|
161
301
|
return false;
|
|
@@ -167,19 +307,15 @@ function equal(a, b, elementsEqual = ordered_1.equal) {
|
|
|
167
307
|
}
|
|
168
308
|
return true;
|
|
169
309
|
}
|
|
170
|
-
exports.equal = equal;
|
|
171
310
|
function equalFn(b, elementsEqual = ordered_1.equal) {
|
|
172
311
|
return a => equal(a, b, elementsEqual);
|
|
173
312
|
}
|
|
174
|
-
exports.equalFn = equalFn;
|
|
175
313
|
function notEqual(a, b, elementsEqual = ordered_1.equal) {
|
|
176
314
|
return !equal(a, b, elementsEqual);
|
|
177
315
|
}
|
|
178
|
-
exports.notEqual = notEqual;
|
|
179
316
|
function notEqualFn(b, elementsEqual = ordered_1.equal) {
|
|
180
317
|
return a => notEqual(a, b, elementsEqual);
|
|
181
318
|
}
|
|
182
|
-
exports.notEqualFn = notEqualFn;
|
|
183
319
|
function prefixMatch(a, b, elementsEqual = ordered_1.equal) {
|
|
184
320
|
if (a.length < b.length) {
|
|
185
321
|
return false;
|
|
@@ -191,11 +327,9 @@ function prefixMatch(a, b, elementsEqual = ordered_1.equal) {
|
|
|
191
327
|
}
|
|
192
328
|
return true;
|
|
193
329
|
}
|
|
194
|
-
exports.prefixMatch = prefixMatch;
|
|
195
330
|
function prefixMatchFn(b, elementsEqual = ordered_1.equal) {
|
|
196
331
|
return a => prefixMatch(a, b, elementsEqual);
|
|
197
332
|
}
|
|
198
|
-
exports.prefixMatchFn = prefixMatchFn;
|
|
199
333
|
/** @internal This implementation is for internal use only, the exported declaration is above */
|
|
200
334
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
201
335
|
// @ts-ignore duplicate identifier: This is the actual implementation, the exported declaration is above.
|
|
@@ -203,27 +337,21 @@ exports.map = Array.from;
|
|
|
203
337
|
function mapFn(f) {
|
|
204
338
|
return array => Array.from(array, f);
|
|
205
339
|
}
|
|
206
|
-
exports.mapFn = mapFn;
|
|
207
340
|
function filter(array, predicate) {
|
|
208
341
|
return nativeFilter.call(array, predicate);
|
|
209
342
|
}
|
|
210
|
-
exports.filter = filter;
|
|
211
343
|
function filterFn(predicate) {
|
|
212
344
|
return array => nativeFilter.call(array, predicate);
|
|
213
345
|
}
|
|
214
|
-
exports.filterFn = filterFn;
|
|
215
346
|
function exclude(array, predicate) {
|
|
216
347
|
return filter(array, (element, index) => !predicate(element, index));
|
|
217
348
|
}
|
|
218
|
-
exports.exclude = exclude;
|
|
219
349
|
function excludeFn(predicate) {
|
|
220
350
|
return array => exclude(array, predicate);
|
|
221
351
|
}
|
|
222
|
-
exports.excludeFn = excludeFn;
|
|
223
352
|
function excludeNull(array) {
|
|
224
353
|
return filter(array, nullable_1.isNotNull);
|
|
225
354
|
}
|
|
226
|
-
exports.excludeNull = excludeNull;
|
|
227
355
|
function excludeFirst(array, predicate) {
|
|
228
356
|
const result = [];
|
|
229
357
|
let i = 0;
|
|
@@ -241,59 +369,45 @@ function excludeFirst(array, predicate) {
|
|
|
241
369
|
}
|
|
242
370
|
return result;
|
|
243
371
|
}
|
|
244
|
-
exports.excludeFirst = excludeFirst;
|
|
245
372
|
function excludeFirstFn(predicate) {
|
|
246
373
|
return array => excludeFirst(array, predicate);
|
|
247
374
|
}
|
|
248
|
-
exports.excludeFirstFn = excludeFirstFn;
|
|
249
375
|
function remove(array, value) {
|
|
250
376
|
return exclude(array, element => element === value);
|
|
251
377
|
}
|
|
252
|
-
exports.remove = remove;
|
|
253
378
|
function removeFn(value) {
|
|
254
379
|
return array => remove(array, value);
|
|
255
380
|
}
|
|
256
|
-
exports.removeFn = removeFn;
|
|
257
381
|
function removeFirst(array, value) {
|
|
258
382
|
return excludeFirst(array, element => element === value);
|
|
259
383
|
}
|
|
260
|
-
exports.removeFirst = removeFirst;
|
|
261
384
|
function removeFirstFn(value) {
|
|
262
385
|
return array => removeFirst(array, value);
|
|
263
386
|
}
|
|
264
|
-
exports.removeFirstFn = removeFirstFn;
|
|
265
387
|
function fold(array, f, initial) {
|
|
266
388
|
return nativeReduce.call(array, f, initial);
|
|
267
389
|
}
|
|
268
|
-
exports.fold = fold;
|
|
269
390
|
function foldFn(f, initial) {
|
|
270
391
|
return array => nativeReduce.call(array, f, initial);
|
|
271
392
|
}
|
|
272
|
-
exports.foldFn = foldFn;
|
|
273
393
|
function fold1(array, f) {
|
|
274
394
|
return nativeReduce.call(array, f);
|
|
275
395
|
}
|
|
276
|
-
exports.fold1 = fold1;
|
|
277
396
|
function fold1Fn(f) {
|
|
278
397
|
return array => fold1(array, f);
|
|
279
398
|
}
|
|
280
|
-
exports.fold1Fn = fold1Fn;
|
|
281
399
|
function foldRight(array, f, initial) {
|
|
282
400
|
return nativeReduceRight.call(array, f, initial);
|
|
283
401
|
}
|
|
284
|
-
exports.foldRight = foldRight;
|
|
285
402
|
function foldRightFn(f, initial) {
|
|
286
403
|
return array => nativeReduceRight.call(array, f, initial);
|
|
287
404
|
}
|
|
288
|
-
exports.foldRightFn = foldRightFn;
|
|
289
405
|
function foldRight1(array, f) {
|
|
290
406
|
return nativeReduceRight.call(array, f);
|
|
291
407
|
}
|
|
292
|
-
exports.foldRight1 = foldRight1;
|
|
293
408
|
function foldRight1Fn(f) {
|
|
294
409
|
return array => foldRight1(array, f);
|
|
295
410
|
}
|
|
296
|
-
exports.foldRight1Fn = foldRight1Fn;
|
|
297
411
|
function foldMap(array, f, m, initial) {
|
|
298
412
|
let accumulator = initial;
|
|
299
413
|
for (let i = 0; i < array.length; ++i) {
|
|
@@ -301,11 +415,9 @@ function foldMap(array, f, m, initial) {
|
|
|
301
415
|
}
|
|
302
416
|
return accumulator;
|
|
303
417
|
}
|
|
304
|
-
exports.foldMap = foldMap;
|
|
305
418
|
function foldMapFn(f, m, initial) {
|
|
306
419
|
return array => foldMap(array, f, m, initial);
|
|
307
420
|
}
|
|
308
|
-
exports.foldMapFn = foldMapFn;
|
|
309
421
|
function foldMapRight(array, f, m, initial) {
|
|
310
422
|
let accumulator = initial;
|
|
311
423
|
const length = array.length;
|
|
@@ -314,28 +426,22 @@ function foldMapRight(array, f, m, initial) {
|
|
|
314
426
|
}
|
|
315
427
|
return accumulator;
|
|
316
428
|
}
|
|
317
|
-
exports.foldMapRight = foldMapRight;
|
|
318
429
|
function foldMapRightFn(f, m, initial) {
|
|
319
430
|
return array => foldMapRight(array, f, m, initial);
|
|
320
431
|
}
|
|
321
|
-
exports.foldMapRightFn = foldMapRightFn;
|
|
322
432
|
function contains(array, value) {
|
|
323
433
|
return nativeIndexOf.call(array, value) !== -1;
|
|
324
434
|
}
|
|
325
|
-
exports.contains = contains;
|
|
326
435
|
function containsFn(value) {
|
|
327
436
|
return array => nativeIndexOf.call(array, value) !== -1;
|
|
328
437
|
}
|
|
329
|
-
exports.containsFn = containsFn;
|
|
330
438
|
function indexOf(array, value) {
|
|
331
439
|
const index = nativeIndexOf.call(array, value);
|
|
332
440
|
return index === -1 ? null : index;
|
|
333
441
|
}
|
|
334
|
-
exports.indexOf = indexOf;
|
|
335
442
|
function indexOfFn(value) {
|
|
336
443
|
return array => indexOf(array, value);
|
|
337
444
|
}
|
|
338
|
-
exports.indexOfFn = indexOfFn;
|
|
339
445
|
function lastIndexOf(array, value) {
|
|
340
446
|
for (let i = array.length - 1; i >= 0; --i) {
|
|
341
447
|
if (array[i] === value) {
|
|
@@ -344,20 +450,16 @@ function lastIndexOf(array, value) {
|
|
|
344
450
|
}
|
|
345
451
|
return null;
|
|
346
452
|
}
|
|
347
|
-
exports.lastIndexOf = lastIndexOf;
|
|
348
453
|
function lastIndexOfFn(value) {
|
|
349
454
|
return array => lastIndexOf(array, value);
|
|
350
455
|
}
|
|
351
|
-
exports.lastIndexOfFn = lastIndexOfFn;
|
|
352
456
|
function findIndex(array, predicate) {
|
|
353
457
|
const index = nativeFindIndex.call(array, predicate);
|
|
354
458
|
return index === -1 ? null : index;
|
|
355
459
|
}
|
|
356
|
-
exports.findIndex = findIndex;
|
|
357
460
|
function findIndexFn(predicate) {
|
|
358
461
|
return array => findIndex(array, predicate);
|
|
359
462
|
}
|
|
360
|
-
exports.findIndexFn = findIndexFn;
|
|
361
463
|
function findLastIndex(array, predicate) {
|
|
362
464
|
for (let i = array.length - 1; i >= 0; --i) {
|
|
363
465
|
if (predicate(array[i], i)) {
|
|
@@ -366,20 +468,16 @@ function findLastIndex(array, predicate) {
|
|
|
366
468
|
}
|
|
367
469
|
return null;
|
|
368
470
|
}
|
|
369
|
-
exports.findLastIndex = findLastIndex;
|
|
370
471
|
function findLastIndexFn(predicate) {
|
|
371
472
|
return array => findLastIndex(array, predicate);
|
|
372
473
|
}
|
|
373
|
-
exports.findLastIndexFn = findLastIndexFn;
|
|
374
474
|
function find(array, predicate) {
|
|
375
475
|
const index = findIndex(array, predicate);
|
|
376
476
|
return index == null ? null : array[index];
|
|
377
477
|
}
|
|
378
|
-
exports.find = find;
|
|
379
478
|
function findFn(predicate) {
|
|
380
479
|
return array => find(array, predicate);
|
|
381
480
|
}
|
|
382
|
-
exports.findFn = findFn;
|
|
383
481
|
function findLast(array, predicate) {
|
|
384
482
|
for (let i = array.length - 1; i >= 0; --i) {
|
|
385
483
|
const element = array[i];
|
|
@@ -389,19 +487,15 @@ function findLast(array, predicate) {
|
|
|
389
487
|
}
|
|
390
488
|
return null;
|
|
391
489
|
}
|
|
392
|
-
exports.findLast = findLast;
|
|
393
490
|
function findLastFn(predicate) {
|
|
394
491
|
return array => findLast(array, predicate);
|
|
395
492
|
}
|
|
396
|
-
exports.findLastFn = findLastFn;
|
|
397
493
|
function maximum(array, compare) {
|
|
398
|
-
return internalMaximum(array, compare
|
|
494
|
+
return internalMaximum(array, compare ?? ordered_1.compare);
|
|
399
495
|
}
|
|
400
|
-
exports.maximum = maximum;
|
|
401
496
|
function maximumFn(compare) {
|
|
402
|
-
return array => internalMaximum(array, compare
|
|
497
|
+
return array => internalMaximum(array, compare ?? ordered_1.compare);
|
|
403
498
|
}
|
|
404
|
-
exports.maximumFn = maximumFn;
|
|
405
499
|
function internalMaximum(array, compare) {
|
|
406
500
|
if (array.length === 0) {
|
|
407
501
|
return null;
|
|
@@ -417,19 +511,15 @@ function internalMaximum(array, compare) {
|
|
|
417
511
|
function maximumBy(array, select) {
|
|
418
512
|
return maximum(array, (a, b) => (0, ordered_1.compare)(select(a), select(b)));
|
|
419
513
|
}
|
|
420
|
-
exports.maximumBy = maximumBy;
|
|
421
514
|
function maximumByFn(select) {
|
|
422
515
|
return array => maximumBy(array, select);
|
|
423
516
|
}
|
|
424
|
-
exports.maximumByFn = maximumByFn;
|
|
425
517
|
function minimum(array, compare) {
|
|
426
|
-
return internalMinimum(array, compare
|
|
518
|
+
return internalMinimum(array, compare ?? ordered_1.compare);
|
|
427
519
|
}
|
|
428
|
-
exports.minimum = minimum;
|
|
429
520
|
function minimumFn(compare) {
|
|
430
|
-
return array => internalMinimum(array, compare
|
|
521
|
+
return array => internalMinimum(array, compare ?? ordered_1.compare);
|
|
431
522
|
}
|
|
432
|
-
exports.minimumFn = minimumFn;
|
|
433
523
|
function internalMinimum(array, compare) {
|
|
434
524
|
if (array.length === 0) {
|
|
435
525
|
return null;
|
|
@@ -445,19 +535,15 @@ function internalMinimum(array, compare) {
|
|
|
445
535
|
function minimumBy(array, select) {
|
|
446
536
|
return minimum(array, (a, b) => (0, ordered_1.compare)(select(a), select(b)));
|
|
447
537
|
}
|
|
448
|
-
exports.minimumBy = minimumBy;
|
|
449
538
|
function minimumByFn(select) {
|
|
450
539
|
return array => minimumBy(array, select);
|
|
451
540
|
}
|
|
452
|
-
exports.minimumByFn = minimumByFn;
|
|
453
541
|
function sum(array) {
|
|
454
542
|
return fold(array, (a, b) => a + b, 0);
|
|
455
543
|
}
|
|
456
|
-
exports.sum = sum;
|
|
457
544
|
function product(array) {
|
|
458
545
|
return fold(array, (a, b) => a * b, 1);
|
|
459
546
|
}
|
|
460
|
-
exports.product = product;
|
|
461
547
|
function average(array) {
|
|
462
548
|
if (array.length === 0) {
|
|
463
549
|
return null;
|
|
@@ -466,55 +552,42 @@ function average(array) {
|
|
|
466
552
|
return sum(array) / array.length;
|
|
467
553
|
}
|
|
468
554
|
}
|
|
469
|
-
exports.average = average;
|
|
470
555
|
function and(array) {
|
|
471
556
|
return findIndex(array, element => !element) == null;
|
|
472
557
|
}
|
|
473
|
-
exports.and = and;
|
|
474
558
|
function or(array) {
|
|
475
559
|
return findIndex(array, element => Boolean(element)) != null;
|
|
476
560
|
}
|
|
477
|
-
exports.or = or;
|
|
478
561
|
function any(array, predicate) {
|
|
479
562
|
return findIndex(array, predicate) != null;
|
|
480
563
|
}
|
|
481
|
-
exports.any = any;
|
|
482
564
|
function anyFn(predicate) {
|
|
483
565
|
return array => any(array, predicate);
|
|
484
566
|
}
|
|
485
|
-
exports.anyFn = anyFn;
|
|
486
567
|
function all(array, predicate) {
|
|
487
568
|
return !any(array, (element, index) => !predicate(element, index));
|
|
488
569
|
}
|
|
489
|
-
exports.all = all;
|
|
490
570
|
function allFn(predicate) {
|
|
491
571
|
return array => all(array, predicate);
|
|
492
572
|
}
|
|
493
|
-
exports.allFn = allFn;
|
|
494
573
|
function concat(arrays) {
|
|
495
574
|
return nativeConcat.apply([], (0, exports.map)(arrays, coerce));
|
|
496
575
|
}
|
|
497
|
-
exports.concat = concat;
|
|
498
576
|
function prepend(a) {
|
|
499
577
|
return b => concat([a, b]);
|
|
500
578
|
}
|
|
501
|
-
exports.prepend = prepend;
|
|
502
579
|
function append(b) {
|
|
503
580
|
return a => concat([a, b]);
|
|
504
581
|
}
|
|
505
|
-
exports.append = append;
|
|
506
582
|
function concatMap(array, f) {
|
|
507
583
|
return concat((0, exports.map)(array, f));
|
|
508
584
|
}
|
|
509
|
-
exports.concatMap = concatMap;
|
|
510
585
|
function concatMapFn(f) {
|
|
511
586
|
return array => concatMap(array, f);
|
|
512
587
|
}
|
|
513
|
-
exports.concatMapFn = concatMapFn;
|
|
514
588
|
function noneNull(array) {
|
|
515
589
|
return any(array, nullable_1.isNull) ? null : array;
|
|
516
590
|
}
|
|
517
|
-
exports.noneNull = noneNull;
|
|
518
591
|
function scan(array, f, initial) {
|
|
519
592
|
const result = (0, exports.copy)({ length: array.length });
|
|
520
593
|
let accumulator = initial;
|
|
@@ -523,11 +596,9 @@ function scan(array, f, initial) {
|
|
|
523
596
|
}
|
|
524
597
|
return result;
|
|
525
598
|
}
|
|
526
|
-
exports.scan = scan;
|
|
527
599
|
function scanFn(f, initial) {
|
|
528
600
|
return array => scan(array, f, initial);
|
|
529
601
|
}
|
|
530
|
-
exports.scanFn = scanFn;
|
|
531
602
|
function scan1(array, f) {
|
|
532
603
|
if (array.length === 0) {
|
|
533
604
|
return [];
|
|
@@ -539,11 +610,9 @@ function scan1(array, f) {
|
|
|
539
610
|
}
|
|
540
611
|
return result;
|
|
541
612
|
}
|
|
542
|
-
exports.scan1 = scan1;
|
|
543
613
|
function scan1Fn(f) {
|
|
544
614
|
return array => scan1(array, f);
|
|
545
615
|
}
|
|
546
|
-
exports.scan1Fn = scan1Fn;
|
|
547
616
|
function scanRight(array, f, initial) {
|
|
548
617
|
const result = (0, exports.copy)({ length: array.length });
|
|
549
618
|
let accumulator = initial;
|
|
@@ -552,11 +621,9 @@ function scanRight(array, f, initial) {
|
|
|
552
621
|
}
|
|
553
622
|
return result;
|
|
554
623
|
}
|
|
555
|
-
exports.scanRight = scanRight;
|
|
556
624
|
function scanRightFn(f, initial) {
|
|
557
625
|
return array => scanRight(array, f, initial);
|
|
558
626
|
}
|
|
559
|
-
exports.scanRightFn = scanRightFn;
|
|
560
627
|
function scanRight1(array, f) {
|
|
561
628
|
if (array.length === 0) {
|
|
562
629
|
return [];
|
|
@@ -568,11 +635,9 @@ function scanRight1(array, f) {
|
|
|
568
635
|
}
|
|
569
636
|
return result;
|
|
570
637
|
}
|
|
571
|
-
exports.scanRight1 = scanRight1;
|
|
572
638
|
function scanRight1Fn(f) {
|
|
573
639
|
return array => scanRight1(array, f);
|
|
574
640
|
}
|
|
575
|
-
exports.scanRight1Fn = scanRight1Fn;
|
|
576
641
|
/** Splits the array at the specified index.
|
|
577
642
|
*
|
|
578
643
|
* Returns a tuple where the first element is the first `index` elements of the
|
|
@@ -580,14 +645,12 @@ exports.scanRight1Fn = scanRight1Fn;
|
|
|
580
645
|
function split(array, index) {
|
|
581
646
|
return [take(array, index), drop(array, index)];
|
|
582
647
|
}
|
|
583
|
-
exports.split = split;
|
|
584
648
|
/** Returns a function that splits an array at the specified index.
|
|
585
649
|
*
|
|
586
650
|
* This is the curried form of {@link split}. */
|
|
587
651
|
function splitFn(index) {
|
|
588
652
|
return array => split(array, index);
|
|
589
653
|
}
|
|
590
|
-
exports.splitFn = splitFn;
|
|
591
654
|
function partition(array, predicate) {
|
|
592
655
|
const a = [];
|
|
593
656
|
const b = [];
|
|
@@ -601,11 +664,9 @@ function partition(array, predicate) {
|
|
|
601
664
|
}
|
|
602
665
|
return [a, b];
|
|
603
666
|
}
|
|
604
|
-
exports.partition = partition;
|
|
605
667
|
function partitionFn(predicate) {
|
|
606
668
|
return array => partition(array, predicate);
|
|
607
669
|
}
|
|
608
|
-
exports.partitionFn = partitionFn;
|
|
609
670
|
function partitionWhile(array, predicate) {
|
|
610
671
|
let i;
|
|
611
672
|
for (i = 0; i < array.length; ++i) {
|
|
@@ -615,19 +676,15 @@ function partitionWhile(array, predicate) {
|
|
|
615
676
|
}
|
|
616
677
|
return [take(array, i), drop(array, i)];
|
|
617
678
|
}
|
|
618
|
-
exports.partitionWhile = partitionWhile;
|
|
619
679
|
function partitionWhileFn(predicate) {
|
|
620
680
|
return array => partitionWhile(array, predicate);
|
|
621
681
|
}
|
|
622
|
-
exports.partitionWhileFn = partitionWhileFn;
|
|
623
682
|
function partitionUntil(array, predicate) {
|
|
624
683
|
return partitionWhile(array, element => !predicate(element));
|
|
625
684
|
}
|
|
626
|
-
exports.partitionUntil = partitionUntil;
|
|
627
685
|
function partitionUntilFn(predicate) {
|
|
628
686
|
return array => partitionUntil(array, predicate);
|
|
629
687
|
}
|
|
630
|
-
exports.partitionUntilFn = partitionUntilFn;
|
|
631
688
|
/** Takes two arrays and returns an array of corresponding pairs.
|
|
632
689
|
*
|
|
633
690
|
* If one of the supplied arrays is shorter than the other, then the excess
|
|
@@ -640,7 +697,6 @@ function zip(a, b) {
|
|
|
640
697
|
}
|
|
641
698
|
return result;
|
|
642
699
|
}
|
|
643
|
-
exports.zip = zip;
|
|
644
700
|
/** Returns a function that combines the elements of `a` with the elements of
|
|
645
701
|
* `b` and returns an array of corresponding pairs.
|
|
646
702
|
*
|
|
@@ -651,14 +707,12 @@ exports.zip = zip;
|
|
|
651
707
|
function zipFn(b) {
|
|
652
708
|
return a => zip(a, b);
|
|
653
709
|
}
|
|
654
|
-
exports.zipFn = zipFn;
|
|
655
710
|
function keyBy(array, f) {
|
|
656
|
-
var _a;
|
|
657
711
|
const result = new Map();
|
|
658
712
|
for (let i = 0; i < array.length; ++i) {
|
|
659
713
|
const element = array[i];
|
|
660
714
|
const key = f(element, i);
|
|
661
|
-
const group =
|
|
715
|
+
const group = result.get(key) ?? [];
|
|
662
716
|
if (!result.has(key)) {
|
|
663
717
|
result.set(key, group);
|
|
664
718
|
}
|
|
@@ -666,11 +720,9 @@ function keyBy(array, f) {
|
|
|
666
720
|
}
|
|
667
721
|
return result;
|
|
668
722
|
}
|
|
669
|
-
exports.keyBy = keyBy;
|
|
670
723
|
function keyByFn(f) {
|
|
671
724
|
return array => keyBy(array, f);
|
|
672
725
|
}
|
|
673
|
-
exports.keyByFn = keyByFn;
|
|
674
726
|
function keyFirstBy(array, f) {
|
|
675
727
|
const result = new Map();
|
|
676
728
|
for (let i = 0; i < array.length; ++i) {
|
|
@@ -682,11 +734,9 @@ function keyFirstBy(array, f) {
|
|
|
682
734
|
}
|
|
683
735
|
return result;
|
|
684
736
|
}
|
|
685
|
-
exports.keyFirstBy = keyFirstBy;
|
|
686
737
|
function keyFirstByFn(f) {
|
|
687
738
|
return array => keyFirstBy(array, f);
|
|
688
739
|
}
|
|
689
|
-
exports.keyFirstByFn = keyFirstByFn;
|
|
690
740
|
function keyLastBy(array, f) {
|
|
691
741
|
const result = new Map();
|
|
692
742
|
for (let i = 0; i < array.length; ++i) {
|
|
@@ -696,17 +746,14 @@ function keyLastBy(array, f) {
|
|
|
696
746
|
}
|
|
697
747
|
return result;
|
|
698
748
|
}
|
|
699
|
-
exports.keyLastBy = keyLastBy;
|
|
700
749
|
function keyLastByFn(f) {
|
|
701
750
|
return array => keyLastBy(array, f);
|
|
702
751
|
}
|
|
703
|
-
exports.keyLastByFn = keyLastByFn;
|
|
704
752
|
function mapKeyBy(array, f) {
|
|
705
|
-
var _a;
|
|
706
753
|
const result = new Map();
|
|
707
754
|
for (let i = 0; i < array.length; ++i) {
|
|
708
755
|
const [key, element] = f(array[i], i);
|
|
709
|
-
const group =
|
|
756
|
+
const group = result.get(key) ?? [];
|
|
710
757
|
if (!result.has(key)) {
|
|
711
758
|
result.set(key, group);
|
|
712
759
|
}
|
|
@@ -714,11 +761,9 @@ function mapKeyBy(array, f) {
|
|
|
714
761
|
}
|
|
715
762
|
return result;
|
|
716
763
|
}
|
|
717
|
-
exports.mapKeyBy = mapKeyBy;
|
|
718
764
|
function mapKeyByFn(f) {
|
|
719
765
|
return array => mapKeyBy(array, f);
|
|
720
766
|
}
|
|
721
|
-
exports.mapKeyByFn = mapKeyByFn;
|
|
722
767
|
function mapKeyFirstBy(array, f) {
|
|
723
768
|
const result = new Map();
|
|
724
769
|
for (let i = 0; i < array.length; ++i) {
|
|
@@ -729,11 +774,9 @@ function mapKeyFirstBy(array, f) {
|
|
|
729
774
|
}
|
|
730
775
|
return result;
|
|
731
776
|
}
|
|
732
|
-
exports.mapKeyFirstBy = mapKeyFirstBy;
|
|
733
777
|
function mapKeyFirstByFn(f) {
|
|
734
778
|
return array => mapKeyFirstBy(array, f);
|
|
735
779
|
}
|
|
736
|
-
exports.mapKeyFirstByFn = mapKeyFirstByFn;
|
|
737
780
|
function mapKeyLastBy(array, f) {
|
|
738
781
|
const result = new Map();
|
|
739
782
|
for (let i = 0; i < array.length; ++i) {
|
|
@@ -742,11 +785,9 @@ function mapKeyLastBy(array, f) {
|
|
|
742
785
|
}
|
|
743
786
|
return result;
|
|
744
787
|
}
|
|
745
|
-
exports.mapKeyLastBy = mapKeyLastBy;
|
|
746
788
|
function mapKeyLastByFn(f) {
|
|
747
789
|
return array => mapKeyLastBy(array, f);
|
|
748
790
|
}
|
|
749
|
-
exports.mapKeyLastByFn = mapKeyLastByFn;
|
|
750
791
|
function group(array, grouping) {
|
|
751
792
|
if ("identity" in grouping) {
|
|
752
793
|
return groupByIdentity(array, grouping.identity);
|
|
@@ -771,19 +812,16 @@ function group(array, grouping) {
|
|
|
771
812
|
return groupByHash(array, grouping.hash);
|
|
772
813
|
}
|
|
773
814
|
}
|
|
774
|
-
exports.group = group;
|
|
775
815
|
function groupFn(grouping) {
|
|
776
816
|
return array => group(array, grouping);
|
|
777
817
|
}
|
|
778
|
-
exports.groupFn = groupFn;
|
|
779
818
|
function groupByIdentity(array, identity = element => element) {
|
|
780
|
-
var _a;
|
|
781
819
|
const groups = [];
|
|
782
820
|
const map = new Map();
|
|
783
821
|
for (let i = 0; i < array.length; ++i) {
|
|
784
822
|
const element = array[i];
|
|
785
823
|
const key = identity(element);
|
|
786
|
-
const group =
|
|
824
|
+
const group = map.get(key) ?? [];
|
|
787
825
|
group.push(element);
|
|
788
826
|
if (!map.has(key)) {
|
|
789
827
|
groups.push(group);
|
|
@@ -792,11 +830,9 @@ function groupByIdentity(array, identity = element => element) {
|
|
|
792
830
|
}
|
|
793
831
|
return groups;
|
|
794
832
|
}
|
|
795
|
-
exports.groupByIdentity = groupByIdentity;
|
|
796
833
|
function groupByIdentityFn(identity) {
|
|
797
834
|
return array => groupByIdentity(array, identity);
|
|
798
835
|
}
|
|
799
|
-
exports.groupByIdentityFn = groupByIdentityFn;
|
|
800
836
|
function groupByEquality(array, equal) {
|
|
801
837
|
const result = [];
|
|
802
838
|
outer: for (let i = 0; i < array.length; ++i) {
|
|
@@ -811,28 +847,23 @@ function groupByEquality(array, equal) {
|
|
|
811
847
|
}
|
|
812
848
|
return result;
|
|
813
849
|
}
|
|
814
|
-
exports.groupByEquality = groupByEquality;
|
|
815
850
|
function groupByEqualityFn(equal) {
|
|
816
851
|
return array => groupByEquality(array, equal);
|
|
817
852
|
}
|
|
818
|
-
exports.groupByEqualityFn = groupByEqualityFn;
|
|
819
853
|
function groupByOrder(array, compare) {
|
|
820
854
|
// TODO: This could use a binary tree to be way more efficient
|
|
821
855
|
return groupByEquality(array, (a, b) => compare(a, b) === ordered_1.Comparison.equal);
|
|
822
856
|
}
|
|
823
|
-
exports.groupByOrder = groupByOrder;
|
|
824
857
|
function groupByOrderFn(compare) {
|
|
825
858
|
return array => groupByOrder(array, compare);
|
|
826
859
|
}
|
|
827
|
-
exports.groupByOrderFn = groupByOrderFn;
|
|
828
860
|
function groupByHash(array, hash) {
|
|
829
|
-
var _a;
|
|
830
861
|
const groups = new Map();
|
|
831
862
|
const result = [];
|
|
832
863
|
for (let i = 0; i < array.length; ++i) {
|
|
833
864
|
const element = array[i];
|
|
834
865
|
const h = hash(element, i);
|
|
835
|
-
const group =
|
|
866
|
+
const group = groups.get(h) ?? [];
|
|
836
867
|
if (!groups.has(h)) {
|
|
837
868
|
result.push(group);
|
|
838
869
|
groups.set(h, group);
|
|
@@ -841,19 +872,16 @@ function groupByHash(array, hash) {
|
|
|
841
872
|
}
|
|
842
873
|
return result;
|
|
843
874
|
}
|
|
844
|
-
exports.groupByHash = groupByHash;
|
|
845
875
|
function groupByHashFn(hash) {
|
|
846
876
|
return array => groupByHash(array, hash);
|
|
847
877
|
}
|
|
848
|
-
exports.groupByHashFn = groupByHashFn;
|
|
849
878
|
function groupByEqualityWithHash(array, equal, hash) {
|
|
850
|
-
var _a;
|
|
851
879
|
const groups = new Map();
|
|
852
880
|
const result = [];
|
|
853
881
|
for (let i = 0; i < array.length; ++i) {
|
|
854
882
|
const element = array[i];
|
|
855
883
|
const h = hash(element, i);
|
|
856
|
-
const hashGroup =
|
|
884
|
+
const hashGroup = groups.get(h) ?? [];
|
|
857
885
|
if (!groups.has(h)) {
|
|
858
886
|
groups.set(h, hashGroup);
|
|
859
887
|
}
|
|
@@ -869,19 +897,15 @@ function groupByEqualityWithHash(array, equal, hash) {
|
|
|
869
897
|
}
|
|
870
898
|
return result;
|
|
871
899
|
}
|
|
872
|
-
exports.groupByEqualityWithHash = groupByEqualityWithHash;
|
|
873
900
|
function groupByEqualityWithHashFn(equal, hash) {
|
|
874
901
|
return array => groupByEqualityWithHash(array, equal, hash);
|
|
875
902
|
}
|
|
876
|
-
exports.groupByEqualityWithHashFn = groupByEqualityWithHashFn;
|
|
877
903
|
function groupByOrderWithHash(array, compare, hash) {
|
|
878
904
|
return groupByEqualityWithHash(array, (a, b) => compare(a, b) === ordered_1.Comparison.equal, hash);
|
|
879
905
|
}
|
|
880
|
-
exports.groupByOrderWithHash = groupByOrderWithHash;
|
|
881
906
|
function groupByOrderWithHashFn(compare, hash) {
|
|
882
907
|
return array => groupByOrderWithHash(array, compare, hash);
|
|
883
908
|
}
|
|
884
|
-
exports.groupByOrderWithHashFn = groupByOrderWithHashFn;
|
|
885
909
|
function groupAdjacent(array, grouping) {
|
|
886
910
|
if ("identity" in grouping) {
|
|
887
911
|
return groupAdjacentByIdentity(array, grouping.identity);
|
|
@@ -896,21 +920,17 @@ function groupAdjacent(array, grouping) {
|
|
|
896
920
|
return groupByHash(array, grouping.hash);
|
|
897
921
|
}
|
|
898
922
|
}
|
|
899
|
-
exports.groupAdjacent = groupAdjacent;
|
|
900
923
|
function groupAdjacentFn(grouping) {
|
|
901
924
|
return array => groupAdjacent(array, grouping);
|
|
902
925
|
}
|
|
903
|
-
exports.groupAdjacentFn = groupAdjacentFn;
|
|
904
926
|
function groupAdjacentByIdentity(array, identity) {
|
|
905
927
|
return identity == null
|
|
906
928
|
? groupAdjacentByEquality(array, (a, b) => a === b)
|
|
907
929
|
: groupAdjacentByEquality(array, (a, b) => identity(a) === identity(b));
|
|
908
930
|
}
|
|
909
|
-
exports.groupAdjacentByIdentity = groupAdjacentByIdentity;
|
|
910
931
|
function groupAdjacentByIdentityFn(identity) {
|
|
911
932
|
return array => groupAdjacentByEquality(array, (a, b) => identity(a) === identity(b));
|
|
912
933
|
}
|
|
913
|
-
exports.groupAdjacentByIdentityFn = groupAdjacentByIdentityFn;
|
|
914
934
|
function groupAdjacentByEquality(array, equal) {
|
|
915
935
|
if (array.length === 0) {
|
|
916
936
|
return [];
|
|
@@ -931,19 +951,15 @@ function groupAdjacentByEquality(array, equal) {
|
|
|
931
951
|
}
|
|
932
952
|
return result;
|
|
933
953
|
}
|
|
934
|
-
exports.groupAdjacentByEquality = groupAdjacentByEquality;
|
|
935
954
|
function groupAdjacentByEqualityFn(equal) {
|
|
936
955
|
return array => groupAdjacentByEquality(array, equal);
|
|
937
956
|
}
|
|
938
|
-
exports.groupAdjacentByEqualityFn = groupAdjacentByEqualityFn;
|
|
939
957
|
function groupAdjacentByOrder(array, compare) {
|
|
940
958
|
return groupAdjacentByEquality(array, (a, b) => compare(a, b) === ordered_1.Comparison.equal);
|
|
941
959
|
}
|
|
942
|
-
exports.groupAdjacentByOrder = groupAdjacentByOrder;
|
|
943
960
|
function groupAdjacentByOrderFn(compare) {
|
|
944
961
|
return array => groupAdjacentByOrder(array, compare);
|
|
945
962
|
}
|
|
946
|
-
exports.groupAdjacentByOrderFn = groupAdjacentByOrderFn;
|
|
947
963
|
function groupAdjacentByHash(array, hash) {
|
|
948
964
|
if (array.length === 0) {
|
|
949
965
|
return [];
|
|
@@ -966,11 +982,9 @@ function groupAdjacentByHash(array, hash) {
|
|
|
966
982
|
}
|
|
967
983
|
return result;
|
|
968
984
|
}
|
|
969
|
-
exports.groupAdjacentByHash = groupAdjacentByHash;
|
|
970
985
|
function groupAdjacentByHashFn(hash) {
|
|
971
986
|
return array => groupAdjacentByHash(array, hash);
|
|
972
987
|
}
|
|
973
|
-
exports.groupAdjacentByHashFn = groupAdjacentByHashFn;
|
|
974
988
|
function unique(array, grouping) {
|
|
975
989
|
if ("identity" in grouping) {
|
|
976
990
|
return uniqueByIdentityInternal(array, grouping.identity);
|
|
@@ -995,15 +1009,12 @@ function unique(array, grouping) {
|
|
|
995
1009
|
return uniqueByHash(array, grouping.hash);
|
|
996
1010
|
}
|
|
997
1011
|
}
|
|
998
|
-
exports.unique = unique;
|
|
999
1012
|
function uniqueFn(grouping) {
|
|
1000
1013
|
return array => unique(array, grouping);
|
|
1001
1014
|
}
|
|
1002
|
-
exports.uniqueFn = uniqueFn;
|
|
1003
1015
|
function uniqueByIdentity(array, identity) {
|
|
1004
|
-
return uniqueByIdentityInternal(array, identity
|
|
1016
|
+
return uniqueByIdentityInternal(array, identity ?? (element => element));
|
|
1005
1017
|
}
|
|
1006
|
-
exports.uniqueByIdentity = uniqueByIdentity;
|
|
1007
1018
|
function uniqueByIdentityInternal(array, identity) {
|
|
1008
1019
|
const set = new Set();
|
|
1009
1020
|
const result = [];
|
|
@@ -1029,20 +1040,16 @@ function uniqueByEquality(array, equal) {
|
|
|
1029
1040
|
}
|
|
1030
1041
|
return result;
|
|
1031
1042
|
}
|
|
1032
|
-
exports.uniqueByEquality = uniqueByEquality;
|
|
1033
1043
|
function uniqueByEqualityFn(equal) {
|
|
1034
1044
|
return array => uniqueByEquality(array, equal);
|
|
1035
1045
|
}
|
|
1036
|
-
exports.uniqueByEqualityFn = uniqueByEqualityFn;
|
|
1037
1046
|
function uniqueByOrder(array, compare) {
|
|
1038
1047
|
return uniqueByEquality(array, (a, b) => compare(a, b) === ordered_1.Comparison.equal);
|
|
1039
1048
|
}
|
|
1040
|
-
exports.uniqueByOrder = uniqueByOrder;
|
|
1041
1049
|
function uniqueByOrderFn(compare) {
|
|
1042
1050
|
// TODO: This could use a binary tree to be more efficient
|
|
1043
1051
|
return array => uniqueByOrder(array, compare);
|
|
1044
1052
|
}
|
|
1045
|
-
exports.uniqueByOrderFn = uniqueByOrderFn;
|
|
1046
1053
|
function uniqueByHash(array, hash) {
|
|
1047
1054
|
const seen = new Set();
|
|
1048
1055
|
const result = [];
|
|
@@ -1056,19 +1063,16 @@ function uniqueByHash(array, hash) {
|
|
|
1056
1063
|
}
|
|
1057
1064
|
return result;
|
|
1058
1065
|
}
|
|
1059
|
-
exports.uniqueByHash = uniqueByHash;
|
|
1060
1066
|
function uniqueByHashFn(hash) {
|
|
1061
1067
|
return array => uniqueByHash(array, hash);
|
|
1062
1068
|
}
|
|
1063
|
-
exports.uniqueByHashFn = uniqueByHashFn;
|
|
1064
1069
|
function uniqueByEqualityWithHash(array, equal, hash) {
|
|
1065
|
-
var _a;
|
|
1066
1070
|
const seenGroups = new Map();
|
|
1067
1071
|
const result = [];
|
|
1068
1072
|
for (let i = 0; i < array.length; ++i) {
|
|
1069
1073
|
const element = array[i];
|
|
1070
1074
|
const h = hash(element, i);
|
|
1071
|
-
const seenGroup =
|
|
1075
|
+
const seenGroup = seenGroups.get(h) ?? [];
|
|
1072
1076
|
if (!seenGroups.has(h)) {
|
|
1073
1077
|
seenGroups.set(h, seenGroup);
|
|
1074
1078
|
}
|
|
@@ -1079,19 +1083,15 @@ function uniqueByEqualityWithHash(array, equal, hash) {
|
|
|
1079
1083
|
}
|
|
1080
1084
|
return result;
|
|
1081
1085
|
}
|
|
1082
|
-
exports.uniqueByEqualityWithHash = uniqueByEqualityWithHash;
|
|
1083
1086
|
function uniqueByEqualityWithHashFn(equal, hash) {
|
|
1084
1087
|
return array => uniqueByEqualityWithHash(array, equal, hash);
|
|
1085
1088
|
}
|
|
1086
|
-
exports.uniqueByEqualityWithHashFn = uniqueByEqualityWithHashFn;
|
|
1087
1089
|
function uniqueByOrderWithHash(array, compare, hash) {
|
|
1088
1090
|
return uniqueByEqualityWithHash(array, (a, b) => compare(a, b) === ordered_1.Comparison.equal, hash);
|
|
1089
1091
|
}
|
|
1090
|
-
exports.uniqueByOrderWithHash = uniqueByOrderWithHash;
|
|
1091
1092
|
function uniqueByOrderWithHashFn(compare, hash) {
|
|
1092
1093
|
return array => uniqueByOrderWithHash(array, compare, hash);
|
|
1093
1094
|
}
|
|
1094
|
-
exports.uniqueByOrderWithHashFn = uniqueByOrderWithHashFn;
|
|
1095
1095
|
function uniqueAdjacent(array, grouping) {
|
|
1096
1096
|
if ("identity" in grouping) {
|
|
1097
1097
|
return uniqueAdjacentByIdentity(array, grouping.identity);
|
|
@@ -1106,21 +1106,17 @@ function uniqueAdjacent(array, grouping) {
|
|
|
1106
1106
|
return uniqueAdjacentByHash(array, grouping.hash);
|
|
1107
1107
|
}
|
|
1108
1108
|
}
|
|
1109
|
-
exports.uniqueAdjacent = uniqueAdjacent;
|
|
1110
1109
|
function uniqueAdjacentFn(grouping) {
|
|
1111
1110
|
return array => uniqueAdjacent(array, grouping);
|
|
1112
1111
|
}
|
|
1113
|
-
exports.uniqueAdjacentFn = uniqueAdjacentFn;
|
|
1114
1112
|
function uniqueAdjacentByIdentity(array, identity) {
|
|
1115
1113
|
return identity == null
|
|
1116
1114
|
? uniqueAdjacentByEquality(array, (a, b) => a === b)
|
|
1117
1115
|
: uniqueAdjacentByEquality(array, (a, b) => identity(a) === identity(b));
|
|
1118
1116
|
}
|
|
1119
|
-
exports.uniqueAdjacentByIdentity = uniqueAdjacentByIdentity;
|
|
1120
1117
|
function uniqueAdjacentByIdentityFn(identity) {
|
|
1121
1118
|
return array => uniqueAdjacentByIdentity(array, identity);
|
|
1122
1119
|
}
|
|
1123
|
-
exports.uniqueAdjacentByIdentityFn = uniqueAdjacentByIdentityFn;
|
|
1124
1120
|
function uniqueAdjacentByEquality(array, equal) {
|
|
1125
1121
|
if (array.length === 0) {
|
|
1126
1122
|
return [];
|
|
@@ -1136,19 +1132,15 @@ function uniqueAdjacentByEquality(array, equal) {
|
|
|
1136
1132
|
}
|
|
1137
1133
|
return result;
|
|
1138
1134
|
}
|
|
1139
|
-
exports.uniqueAdjacentByEquality = uniqueAdjacentByEquality;
|
|
1140
1135
|
function uniqueAdjacentByEqualityFn(equal) {
|
|
1141
1136
|
return array => uniqueAdjacentByEquality(array, equal);
|
|
1142
1137
|
}
|
|
1143
|
-
exports.uniqueAdjacentByEqualityFn = uniqueAdjacentByEqualityFn;
|
|
1144
1138
|
function uniqueAdjacentByOrder(array, compare) {
|
|
1145
1139
|
return uniqueAdjacentByEquality(array, (a, b) => compare(a, b) === ordered_1.Comparison.equal);
|
|
1146
1140
|
}
|
|
1147
|
-
exports.uniqueAdjacentByOrder = uniqueAdjacentByOrder;
|
|
1148
1141
|
function uniqueAdjacentByOrderFn(compare) {
|
|
1149
1142
|
return array => uniqueAdjacentByOrder(array, compare);
|
|
1150
1143
|
}
|
|
1151
|
-
exports.uniqueAdjacentByOrderFn = uniqueAdjacentByOrderFn;
|
|
1152
1144
|
function uniqueAdjacentByHash(array, hash) {
|
|
1153
1145
|
if (array.length === 0) {
|
|
1154
1146
|
return [];
|
|
@@ -1166,44 +1158,34 @@ function uniqueAdjacentByHash(array, hash) {
|
|
|
1166
1158
|
}
|
|
1167
1159
|
return result;
|
|
1168
1160
|
}
|
|
1169
|
-
exports.uniqueAdjacentByHash = uniqueAdjacentByHash;
|
|
1170
1161
|
function uniqueAdjacentByHashFn(hash) {
|
|
1171
1162
|
return array => uniqueAdjacentByHash(array, hash);
|
|
1172
1163
|
}
|
|
1173
|
-
exports.uniqueAdjacentByHashFn = uniqueAdjacentByHashFn;
|
|
1174
1164
|
function sort(array, comparator) {
|
|
1175
|
-
return (0, exports.copy)(array).sort(comparator
|
|
1165
|
+
return (0, exports.copy)(array).sort(comparator ?? ordered_1.compare);
|
|
1176
1166
|
}
|
|
1177
|
-
exports.sort = sort;
|
|
1178
1167
|
function sortFn(comparator) {
|
|
1179
1168
|
return array => sort(array, comparator);
|
|
1180
1169
|
}
|
|
1181
|
-
exports.sortFn = sortFn;
|
|
1182
1170
|
function sortBy(array, select) {
|
|
1183
1171
|
return sort(array, (a, b) => ordered_1.compare(select(a), select(b)));
|
|
1184
1172
|
}
|
|
1185
|
-
exports.sortBy = sortBy;
|
|
1186
1173
|
function sortByFn(select) {
|
|
1187
1174
|
return array => sortBy(array, select);
|
|
1188
1175
|
}
|
|
1189
|
-
exports.sortByFn = sortByFn;
|
|
1190
1176
|
function sortByDescending(array, select) {
|
|
1191
1177
|
return sort(array, (a, b) => -ordered_1.compare(select(a), select(b)));
|
|
1192
1178
|
}
|
|
1193
|
-
exports.sortByDescending = sortByDescending;
|
|
1194
1179
|
function sortByDescendingFn(select) {
|
|
1195
1180
|
return array => sortByDescending(array, select);
|
|
1196
1181
|
}
|
|
1197
|
-
exports.sortByDescendingFn = sortByDescendingFn;
|
|
1198
1182
|
function forEach(array, f) {
|
|
1199
1183
|
for (let i = 0; i < array.length; ++i) {
|
|
1200
1184
|
f(array[i], i);
|
|
1201
1185
|
}
|
|
1202
1186
|
return array;
|
|
1203
1187
|
}
|
|
1204
|
-
exports.forEach = forEach;
|
|
1205
1188
|
function forEachFn(f) {
|
|
1206
1189
|
return array => forEach(array, f);
|
|
1207
1190
|
}
|
|
1208
|
-
exports.forEachFn = forEachFn;
|
|
1209
1191
|
//# sourceMappingURL=index.js.map
|