scats 1.3.0 → 1.3.2
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/dist/abstract-map.js +1 -1
- package/dist/array-iterable.js +7 -7
- package/dist/collection.js +16 -16
- package/dist/either.js +8 -8
- package/dist/hashset.js +1 -1
- package/dist/index.js +8 -8
- package/dist/mutable/hashmap.js +1 -1
- package/dist/mutable/hashset.js +1 -1
- package/dist/option.js +3 -3
- package/dist/try.js +6 -6
- package/dist/util.js +6 -6
- package/package.json +1 -1
- package/src/collection.ts +11 -8
package/dist/abstract-map.js
CHANGED
|
@@ -17,7 +17,7 @@ class AbstractMap extends array_iterable_1.ArrayIterable {
|
|
|
17
17
|
return this.map.size <= 0;
|
|
18
18
|
}
|
|
19
19
|
get(key) {
|
|
20
|
-
return option_1.option(this.map.get(key));
|
|
20
|
+
return (0, option_1.option)(this.map.get(key));
|
|
21
21
|
}
|
|
22
22
|
getOrElse(key, defaultValue) {
|
|
23
23
|
return this.get(key).getOrElse(defaultValue);
|
package/dist/array-iterable.js
CHANGED
|
@@ -38,7 +38,7 @@ class ArrayIterable {
|
|
|
38
38
|
return this.toArray.find(i => p(i)) !== undefined;
|
|
39
39
|
}
|
|
40
40
|
find(p) {
|
|
41
|
-
return index_1.option(this.toArray.find(i => p(i)));
|
|
41
|
+
return (0, index_1.option)(this.toArray.find(i => p(i)));
|
|
42
42
|
}
|
|
43
43
|
count(p) {
|
|
44
44
|
let res = 0;
|
|
@@ -65,7 +65,7 @@ class ArrayIterable {
|
|
|
65
65
|
return this.reduceLeftOption(op);
|
|
66
66
|
}
|
|
67
67
|
get headOption() {
|
|
68
|
-
return this.isEmpty ? index_1.none : index_1.some(this.head);
|
|
68
|
+
return this.isEmpty ? index_1.none : (0, index_1.some)(this.head);
|
|
69
69
|
}
|
|
70
70
|
get head() {
|
|
71
71
|
if (this.isEmpty) {
|
|
@@ -76,7 +76,7 @@ class ArrayIterable {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
get lastOption() {
|
|
79
|
-
return this.isEmpty ? index_1.none : index_1.some(this.last);
|
|
79
|
+
return this.isEmpty ? index_1.none : (0, index_1.some)(this.last);
|
|
80
80
|
}
|
|
81
81
|
get last() {
|
|
82
82
|
if (this.isEmpty) {
|
|
@@ -100,7 +100,7 @@ class ArrayIterable {
|
|
|
100
100
|
return acc;
|
|
101
101
|
}
|
|
102
102
|
reduceLeftOption(op) {
|
|
103
|
-
return this.isEmpty ? index_1.none : index_1.some(this.reduceLeft(op));
|
|
103
|
+
return this.isEmpty ? index_1.none : (0, index_1.some)(this.reduceLeft(op));
|
|
104
104
|
}
|
|
105
105
|
foldRight(initial) {
|
|
106
106
|
return (op) => {
|
|
@@ -123,7 +123,7 @@ class ArrayIterable {
|
|
|
123
123
|
return acc;
|
|
124
124
|
}
|
|
125
125
|
reduceRightOption(op) {
|
|
126
|
-
return this.isEmpty ? index_1.none : index_1.some(this.reduceRight(op));
|
|
126
|
+
return this.isEmpty ? index_1.none : (0, index_1.some)(this.reduceRight(op));
|
|
127
127
|
}
|
|
128
128
|
foldLeft(initial) {
|
|
129
129
|
return (op) => {
|
|
@@ -158,7 +158,7 @@ class ArrayIterable {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
minByOption(toNumber) {
|
|
161
|
-
return this.isEmpty ? index_1.none : index_1.some(this.minBy(toNumber));
|
|
161
|
+
return this.isEmpty ? index_1.none : (0, index_1.some)(this.minBy(toNumber));
|
|
162
162
|
}
|
|
163
163
|
maxBy(toNumber) {
|
|
164
164
|
if (this.isEmpty) {
|
|
@@ -178,7 +178,7 @@ class ArrayIterable {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
maxByOption(toNumber) {
|
|
181
|
-
return this.isEmpty ? index_1.none : index_1.some(this.maxBy(toNumber));
|
|
181
|
+
return this.isEmpty ? index_1.none : (0, index_1.some)(this.maxBy(toNumber));
|
|
182
182
|
}
|
|
183
183
|
partition(p) {
|
|
184
184
|
const array = this.toArray;
|
package/dist/collection.js
CHANGED
|
@@ -103,9 +103,9 @@ class Collection extends ArrayBackedCollection {
|
|
|
103
103
|
return new Collection(this.items.map(i => f(i)));
|
|
104
104
|
}
|
|
105
105
|
flatMap(f) {
|
|
106
|
-
|
|
106
|
+
let res = [];
|
|
107
107
|
this.items.forEach(i => {
|
|
108
|
-
res.
|
|
108
|
+
res = res.concat(f(i).items);
|
|
109
109
|
});
|
|
110
110
|
return new Collection(res);
|
|
111
111
|
}
|
|
@@ -119,7 +119,7 @@ class Collection extends ArrayBackedCollection {
|
|
|
119
119
|
return new Collection(res);
|
|
120
120
|
}
|
|
121
121
|
mapPromise(f) {
|
|
122
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
123
123
|
const res = [];
|
|
124
124
|
for (let i = 0; i < this.items.length; i++) {
|
|
125
125
|
res.push(yield f(this.items[i]));
|
|
@@ -128,22 +128,22 @@ class Collection extends ArrayBackedCollection {
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
mapPromiseAll(f) {
|
|
131
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
132
132
|
return new Collection(yield Promise.all(this.items.map(i => f(i))));
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
flatMapPromise(f) {
|
|
136
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
|
|
136
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
137
|
+
let res = [];
|
|
138
138
|
for (let i = 0; i < this.items.length; i++) {
|
|
139
139
|
const item = this.items[i];
|
|
140
|
-
res.
|
|
140
|
+
res = res.concat((yield f(item)).items);
|
|
141
141
|
}
|
|
142
142
|
return new Collection(res);
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
flatMapPromiseAll(f) {
|
|
146
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
147
147
|
return (yield this.mapPromiseAll(f)).flatten();
|
|
148
148
|
});
|
|
149
149
|
}
|
|
@@ -329,9 +329,9 @@ class ArrayBuffer extends ArrayBackedCollection {
|
|
|
329
329
|
return new Collection(this.items.slice(0));
|
|
330
330
|
}
|
|
331
331
|
flatMap(f) {
|
|
332
|
-
|
|
332
|
+
let res = [];
|
|
333
333
|
this.items.forEach(i => {
|
|
334
|
-
res.
|
|
334
|
+
res = res.concat(f(i).items);
|
|
335
335
|
});
|
|
336
336
|
return new ArrayBuffer(res);
|
|
337
337
|
}
|
|
@@ -345,11 +345,11 @@ class ArrayBuffer extends ArrayBackedCollection {
|
|
|
345
345
|
return new ArrayBuffer(res);
|
|
346
346
|
}
|
|
347
347
|
flatMapPromise(f) {
|
|
348
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
349
|
-
|
|
348
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
349
|
+
let res = [];
|
|
350
350
|
for (let i = 0; i < this.items.length; i++) {
|
|
351
351
|
const item = this.items[i];
|
|
352
|
-
res.
|
|
352
|
+
res = res.concat((yield f(item)).items);
|
|
353
353
|
}
|
|
354
354
|
return new ArrayBuffer(res);
|
|
355
355
|
});
|
|
@@ -358,7 +358,7 @@ class ArrayBuffer extends ArrayBackedCollection {
|
|
|
358
358
|
return new ArrayBuffer(this.items.map(i => f(i)));
|
|
359
359
|
}
|
|
360
360
|
mapPromise(f) {
|
|
361
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
362
362
|
const res = [];
|
|
363
363
|
for (let i = 0; i < this.items.length; i++) {
|
|
364
364
|
res.push(yield f(this.items[i]));
|
|
@@ -367,12 +367,12 @@ class ArrayBuffer extends ArrayBackedCollection {
|
|
|
367
367
|
});
|
|
368
368
|
}
|
|
369
369
|
mapPromiseAll(f) {
|
|
370
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
371
371
|
return new ArrayBuffer(yield Promise.all(this.items.map(i => f(i))));
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
flatMapPromiseAll(f) {
|
|
375
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
375
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
376
376
|
return (yield this.mapPromiseAll(f)).flatten();
|
|
377
377
|
});
|
|
378
378
|
}
|
package/dist/either.js
CHANGED
|
@@ -93,9 +93,9 @@ class Either {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
mapPromise(f) {
|
|
96
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
97
97
|
return this.match({
|
|
98
|
-
right: (v) => tslib_1.__awaiter(this, void 0, void 0, function* () { return right(yield f(v)); }),
|
|
98
|
+
right: (v) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { return right(yield f(v)); }),
|
|
99
99
|
left: () => Promise.resolve(this)
|
|
100
100
|
});
|
|
101
101
|
});
|
|
@@ -120,14 +120,14 @@ class Either {
|
|
|
120
120
|
}
|
|
121
121
|
get toOption() {
|
|
122
122
|
return this.match({
|
|
123
|
-
right: v => option_1.some(v),
|
|
123
|
+
right: v => (0, option_1.some)(v),
|
|
124
124
|
left: () => option_1.none
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
toTry(toError = util_1.toErrorConversion) {
|
|
128
128
|
return this.match({
|
|
129
|
-
right: (b) => try_1.success(b),
|
|
130
|
-
left: (e) => try_1.failure(toError(e))
|
|
129
|
+
right: (b) => (0, try_1.success)(b),
|
|
130
|
+
left: (e) => (0, try_1.failure)(toError(e))
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -171,7 +171,7 @@ exports.Right = Right;
|
|
|
171
171
|
}
|
|
172
172
|
mapPromise(f) {
|
|
173
173
|
return this.e.match({
|
|
174
|
-
left: (v) => tslib_1.__awaiter(this, void 0, void 0, function* () { return left(yield f(v)); }),
|
|
174
|
+
left: (v) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { return left(yield f(v)); }),
|
|
175
175
|
right: () => Promise.resolve(this.e)
|
|
176
176
|
});
|
|
177
177
|
}
|
|
@@ -226,7 +226,7 @@ exports.Right = Right;
|
|
|
226
226
|
}
|
|
227
227
|
filterToOption(p) {
|
|
228
228
|
return this.e.match({
|
|
229
|
-
left: l => p(l) ? option_1.some(this.e) : option_1.none,
|
|
229
|
+
left: l => p(l) ? (0, option_1.some)(this.e) : option_1.none,
|
|
230
230
|
right: () => option_1.none
|
|
231
231
|
});
|
|
232
232
|
}
|
|
@@ -238,7 +238,7 @@ exports.Right = Right;
|
|
|
238
238
|
}
|
|
239
239
|
get toOption() {
|
|
240
240
|
return this.e.match({
|
|
241
|
-
left: l => option_1.some(l),
|
|
241
|
+
left: l => (0, option_1.some)(l),
|
|
242
242
|
right: () => option_1.none
|
|
243
243
|
});
|
|
244
244
|
}
|
package/dist/hashset.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.HashSet = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const hashmap_1 = require("./hashmap");
|
|
6
6
|
const abstract_set_1 = require("./abstract-set");
|
|
7
|
-
const mutable = tslib_1.__importStar(require("./mutable/hashset"));
|
|
7
|
+
const mutable = (0, tslib_1.__importStar)(require("./mutable/hashset"));
|
|
8
8
|
class HashSet extends abstract_set_1.AbstractSet {
|
|
9
9
|
constructor(items) {
|
|
10
10
|
super(items);
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mutable = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./collection"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./either"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./hashmap"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./hashset"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./option"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./try"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./util"), exports);
|
|
12
|
-
const mutable = tslib_1.__importStar(require("./mutable"));
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./collection"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./either"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./hashmap"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./hashset"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./option"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./try"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./util"), exports);
|
|
12
|
+
const mutable = (0, tslib_1.__importStar)(require("./mutable"));
|
|
13
13
|
exports.mutable = mutable;
|
package/dist/mutable/hashmap.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HashMap = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const abstract_map_1 = require("../abstract-map");
|
|
6
|
-
const immutable = tslib_1.__importStar(require("../hashmap"));
|
|
6
|
+
const immutable = (0, tslib_1.__importStar)(require("../hashmap"));
|
|
7
7
|
class HashMap extends abstract_map_1.AbstractMap {
|
|
8
8
|
constructor(map = new Map()) {
|
|
9
9
|
super(map);
|
package/dist/mutable/hashset.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HashSet = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const abstract_set_1 = require("../abstract-set");
|
|
6
|
-
const immutable = tslib_1.__importStar(require("../hashset"));
|
|
6
|
+
const immutable = (0, tslib_1.__importStar)(require("../hashset"));
|
|
7
7
|
class HashSet extends abstract_set_1.AbstractSet {
|
|
8
8
|
constructor(items = new Set()) {
|
|
9
9
|
super(items);
|
package/dist/option.js
CHANGED
|
@@ -60,7 +60,7 @@ class Option extends array_iterable_1.ArrayIterable {
|
|
|
60
60
|
return this.isEmpty ? exports.none : p(this.get);
|
|
61
61
|
}
|
|
62
62
|
mapPromise(f) {
|
|
63
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
64
64
|
if (this.isEmpty) {
|
|
65
65
|
return Promise.resolve(exports.none);
|
|
66
66
|
}
|
|
@@ -129,10 +129,10 @@ class Option extends array_iterable_1.ArrayIterable {
|
|
|
129
129
|
return this.isEmpty ? collection_1.Collection.empty : collection_1.Collection.of(this.get);
|
|
130
130
|
}
|
|
131
131
|
toRight(left) {
|
|
132
|
-
return this.isEmpty ? new either_1.Left(left()) : either_1.right(this.get);
|
|
132
|
+
return this.isEmpty ? new either_1.Left(left()) : (0, either_1.right)(this.get);
|
|
133
133
|
}
|
|
134
134
|
toLeft(right) {
|
|
135
|
-
return this.isEmpty ? new either_1.Right(right()) : either_1.left(this.get);
|
|
135
|
+
return this.isEmpty ? new either_1.Right(right()) : (0, either_1.left)(this.get);
|
|
136
136
|
}
|
|
137
137
|
get toArray() {
|
|
138
138
|
return this.isEmpty ? [] : [this.get];
|
package/dist/try.js
CHANGED
|
@@ -7,7 +7,7 @@ const either_1 = require("./either");
|
|
|
7
7
|
const util_1 = require("./util");
|
|
8
8
|
class TryLike {
|
|
9
9
|
mapPromise(f) {
|
|
10
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
11
11
|
return this.match({
|
|
12
12
|
success: r => Try.promise(() => f(r)),
|
|
13
13
|
failure: () => Promise.resolve(this)
|
|
@@ -41,8 +41,8 @@ class TryLike {
|
|
|
41
41
|
}
|
|
42
42
|
toEitherWithLeft(f) {
|
|
43
43
|
return this.match({
|
|
44
|
-
success: r => either_1.right(r),
|
|
45
|
-
failure: e => either_1.left(f(e))
|
|
44
|
+
success: r => (0, either_1.right)(r),
|
|
45
|
+
failure: e => (0, either_1.left)(f(e))
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -55,10 +55,10 @@ class Success extends TryLike {
|
|
|
55
55
|
this.isFailure = false;
|
|
56
56
|
}
|
|
57
57
|
get toOption() {
|
|
58
|
-
return option_1.some(this.result);
|
|
58
|
+
return (0, option_1.some)(this.result);
|
|
59
59
|
}
|
|
60
60
|
get toEither() {
|
|
61
|
-
return either_1.right(this.result);
|
|
61
|
+
return (0, either_1.right)(this.result);
|
|
62
62
|
}
|
|
63
63
|
map(f) {
|
|
64
64
|
return success(f(this.result));
|
|
@@ -132,7 +132,7 @@ class Failure extends TryLike {
|
|
|
132
132
|
return option_1.none;
|
|
133
133
|
}
|
|
134
134
|
get toEither() {
|
|
135
|
-
return either_1.left(this.error);
|
|
135
|
+
return (0, either_1.left)(this.error);
|
|
136
136
|
}
|
|
137
137
|
map(_) {
|
|
138
138
|
return this;
|
package/dist/util.js
CHANGED
|
@@ -23,7 +23,7 @@ class StepWithFilter {
|
|
|
23
23
|
this.filter = filter;
|
|
24
24
|
}
|
|
25
25
|
if(condition) {
|
|
26
|
-
return new StepWithFilter(this.name, this.f, option_1.some(condition));
|
|
26
|
+
return new StepWithFilter(this.name, this.f, (0, option_1.some)(condition));
|
|
27
27
|
}
|
|
28
28
|
invokeStep(state) {
|
|
29
29
|
const result = this.f(state);
|
|
@@ -43,10 +43,10 @@ class TaskWithFilter {
|
|
|
43
43
|
this.filter = filter;
|
|
44
44
|
}
|
|
45
45
|
if(condition) {
|
|
46
|
-
return new TaskWithFilter(this.name, this.f, option_1.some(condition));
|
|
46
|
+
return new TaskWithFilter(this.name, this.f, (0, option_1.some)(condition));
|
|
47
47
|
}
|
|
48
48
|
invokeStep(state) {
|
|
49
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
50
50
|
const result = yield this.f(state);
|
|
51
51
|
return this.filter.filter(() => 'filter' in result).map(filter => {
|
|
52
52
|
return result.filter(x => {
|
|
@@ -59,11 +59,11 @@ class TaskWithFilter {
|
|
|
59
59
|
}
|
|
60
60
|
exports.TaskWithFilter = TaskWithFilter;
|
|
61
61
|
function step(name, f) {
|
|
62
|
-
return new StepWithFilter(option_1.some(name), f, option_1.none);
|
|
62
|
+
return new StepWithFilter((0, option_1.some)(name), f, option_1.none);
|
|
63
63
|
}
|
|
64
64
|
exports.step = step;
|
|
65
65
|
function task(name, f) {
|
|
66
|
-
return new TaskWithFilter(option_1.some(name), f, option_1.none);
|
|
66
|
+
return new TaskWithFilter((0, option_1.some)(name), f, option_1.none);
|
|
67
67
|
}
|
|
68
68
|
exports.task = task;
|
|
69
69
|
function forComprehension(...steps) {
|
|
@@ -94,7 +94,7 @@ exports.forComprehension = forComprehension;
|
|
|
94
94
|
return {
|
|
95
95
|
yield: function (final) {
|
|
96
96
|
function processStep(stepIdx, acc) {
|
|
97
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
98
98
|
const result = yield steps[stepIdx].invokeStep(acc);
|
|
99
99
|
if (stepIdx < steps.length - 1) {
|
|
100
100
|
return yield result.flatMapPromise(x => {
|
package/package.json
CHANGED
package/src/collection.ts
CHANGED
|
@@ -133,9 +133,10 @@ export class Collection<T> extends ArrayBackedCollection<T, Collection<T>> imple
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
flatMap<B>(f: (item: T) => Collection<B>): Collection<B> {
|
|
136
|
-
|
|
136
|
+
//https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
|
|
137
|
+
let res: B[] = [];
|
|
137
138
|
this.items.forEach(i => {
|
|
138
|
-
res.
|
|
139
|
+
res = res.concat(f(i).items);
|
|
139
140
|
});
|
|
140
141
|
return new Collection<B>(res);
|
|
141
142
|
}
|
|
@@ -201,10 +202,10 @@ export class Collection<T> extends ArrayBackedCollection<T, Collection<T>> imple
|
|
|
201
202
|
* @param f
|
|
202
203
|
*/
|
|
203
204
|
async flatMapPromise<B>(f: (item: T) => Promise<Collection<B>>): Promise<Collection<B>> {
|
|
204
|
-
|
|
205
|
+
let res: B[] = [];
|
|
205
206
|
for (let i = 0; i < this.items.length; i++) {
|
|
206
207
|
const item = this.items[i];
|
|
207
|
-
res.
|
|
208
|
+
res = res.concat((await f(item)).items);
|
|
208
209
|
}
|
|
209
210
|
return new Collection<B>(res);
|
|
210
211
|
}
|
|
@@ -550,9 +551,10 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
|
|
|
550
551
|
* `f` to each element of this $coll and concatenating the results.
|
|
551
552
|
*/
|
|
552
553
|
flatMap<B>(f: (item: T) => ArrayBuffer<B>): ArrayBuffer<B> {
|
|
553
|
-
|
|
554
|
+
//https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
|
|
555
|
+
let res: B[] = [];
|
|
554
556
|
this.items.forEach(i => {
|
|
555
|
-
res.
|
|
557
|
+
res = res.concat(f(i).items);
|
|
556
558
|
});
|
|
557
559
|
return new ArrayBuffer<B>(res);
|
|
558
560
|
}
|
|
@@ -569,10 +571,11 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
|
|
|
569
571
|
|
|
570
572
|
|
|
571
573
|
async flatMapPromise<B>(f: (item: T) => Promise<ArrayBuffer<B>>): Promise<ArrayBuffer<B>> {
|
|
572
|
-
|
|
574
|
+
//https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
|
|
575
|
+
let res: B[] = [];
|
|
573
576
|
for (let i = 0; i < this.items.length; i++) {
|
|
574
577
|
const item = this.items[i];
|
|
575
|
-
res.
|
|
578
|
+
res = res.concat((await f(item)).items);
|
|
576
579
|
}
|
|
577
580
|
return new ArrayBuffer<B>(res);
|
|
578
581
|
}
|