scats 1.2.0 → 1.3.1

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/README.md CHANGED
@@ -413,8 +413,8 @@ set.add(1); // true. set = [1]
413
413
  set.add(1); // false. set = [1]
414
414
  set.clear(); // []]
415
415
  set.add(1); // true. set = [1]
416
- set.remove(2); false. set = [1]
417
- set.remove(1); true. set = []
418
- set.addAll([2, 3]); set = [1, 2, 3]
416
+ set.remove(2); // false. set = [1]
417
+ set.remove(1); // true. set = []
418
+ set.addAll([2, 3]); // set = [1, 2, 3]
419
419
  set.filterInPlace(x => x > 2); // [3]
420
420
  ```
@@ -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);
@@ -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;
@@ -47,11 +47,12 @@ export declare const Nil: Collection<any>;
47
47
  export declare class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> implements Mappable<T>, Filterable<T, ArrayBuffer<T>> {
48
48
  protected readonly items: T[];
49
49
  static get empty(): ArrayBuffer<any>;
50
- constructor(items: T[]);
50
+ constructor(items?: T[]);
51
51
  static of<T>(...elements: T[]): ArrayBuffer<T>;
52
52
  static from<T>(elements: Iterable<T>): ArrayBuffer<T>;
53
53
  static fill<A>(len: number): (elem: (idx: number) => A) => ArrayBuffer<A>;
54
54
  protected fromArray(array: T[]): ArrayBuffer<T>;
55
+ private normalized;
55
56
  update(index: number, element: T): void;
56
57
  set(index: number, element: T): void;
57
58
  clear(): void;
@@ -65,6 +66,12 @@ export declare class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer
65
66
  subtractOne(element: T): this;
66
67
  subtractAll(elements: Iterable<T>): this;
67
68
  sort(compareFn?: (a: T, b: T) => number): this;
69
+ filterInPlace(p: (element: T) => boolean): this;
70
+ dropInPlace(n: number): this;
71
+ dropRightInPlace(n: number): this;
72
+ takeInPlace(n: number): this;
73
+ takeRightInPlace(n: number): this;
74
+ sliceInPlace(start: number, end: number): this;
68
75
  get toCollection(): Collection<T>;
69
76
  flatMap<B>(f: (item: T) => ArrayBuffer<B>): ArrayBuffer<B>;
70
77
  flatMapOption<B>(f: (item: T) => Option<B>): ArrayBuffer<B>;
@@ -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,12 +128,12 @@ 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* () {
136
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
137
137
  const res = [];
138
138
  for (let i = 0; i < this.items.length; i++) {
139
139
  const item = this.items[i];
@@ -143,7 +143,7 @@ class Collection extends ArrayBackedCollection {
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
  }
@@ -187,7 +187,7 @@ exports.Collection = Collection;
187
187
  Collection.empty = new Collection([]);
188
188
  exports.Nil = Collection.empty;
189
189
  class ArrayBuffer extends ArrayBackedCollection {
190
- constructor(items) {
190
+ constructor(items = []) {
191
191
  super();
192
192
  this.items = items;
193
193
  }
@@ -217,6 +217,9 @@ class ArrayBuffer extends ArrayBackedCollection {
217
217
  return new ArrayBuffer(array);
218
218
  }
219
219
  }
220
+ normalized(n) {
221
+ return Math.min(Math.max(n, 0), this.length);
222
+ }
220
223
  update(index, element) {
221
224
  this.checkWithinBounds(index, index + 1);
222
225
  this.items[index] = element;
@@ -283,13 +286,52 @@ class ArrayBuffer extends ArrayBackedCollection {
283
286
  this.items.sort(compareFn);
284
287
  return this;
285
288
  }
289
+ filterInPlace(p) {
290
+ let i = 0, j = 0;
291
+ while (i < this.size) {
292
+ if (p(this.items[i])) {
293
+ if (i != j) {
294
+ this.items[j] = this.items[i];
295
+ }
296
+ j += 1;
297
+ }
298
+ i += 1;
299
+ }
300
+ if (i == j) {
301
+ return this;
302
+ }
303
+ else {
304
+ return this.takeInPlace(j);
305
+ }
306
+ }
307
+ dropInPlace(n) {
308
+ this.remove(0, this.normalized(n));
309
+ return this;
310
+ }
311
+ dropRightInPlace(n) {
312
+ const norm = this.normalized(n);
313
+ this.remove(this.length - norm, norm);
314
+ return this;
315
+ }
316
+ takeInPlace(n) {
317
+ const norm = this.normalized(n);
318
+ this.remove(norm, this.length - norm);
319
+ return this;
320
+ }
321
+ takeRightInPlace(n) {
322
+ this.remove(0, this.length - this.normalized(n));
323
+ return this;
324
+ }
325
+ sliceInPlace(start, end) {
326
+ return this.takeInPlace(end).dropInPlace(start);
327
+ }
286
328
  get toCollection() {
287
329
  return new Collection(this.items.slice(0));
288
330
  }
289
331
  flatMap(f) {
290
- const res = [];
332
+ let res = [];
291
333
  this.items.forEach(i => {
292
- res.push(...f(i).items);
334
+ res = res.concat(...f(i).items);
293
335
  });
294
336
  return new ArrayBuffer(res);
295
337
  }
@@ -303,11 +345,11 @@ class ArrayBuffer extends ArrayBackedCollection {
303
345
  return new ArrayBuffer(res);
304
346
  }
305
347
  flatMapPromise(f) {
306
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
307
- const res = [];
348
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
349
+ let res = [];
308
350
  for (let i = 0; i < this.items.length; i++) {
309
351
  const item = this.items[i];
310
- res.push(...(yield f(item)).items);
352
+ res = res.concat((yield f(item)).items);
311
353
  }
312
354
  return new ArrayBuffer(res);
313
355
  });
@@ -316,7 +358,7 @@ class ArrayBuffer extends ArrayBackedCollection {
316
358
  return new ArrayBuffer(this.items.map(i => f(i)));
317
359
  }
318
360
  mapPromise(f) {
319
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
361
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
320
362
  const res = [];
321
363
  for (let i = 0; i < this.items.length; i++) {
322
364
  res.push(yield f(this.items[i]));
@@ -325,12 +367,12 @@ class ArrayBuffer extends ArrayBackedCollection {
325
367
  });
326
368
  }
327
369
  mapPromiseAll(f) {
328
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
370
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
329
371
  return new ArrayBuffer(yield Promise.all(this.items.map(i => f(i))));
330
372
  });
331
373
  }
332
374
  flatMapPromiseAll(f) {
333
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
375
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
334
376
  return (yield this.mapPromiseAll(f)).flatten();
335
377
  });
336
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;
@@ -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);
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scats",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Useful scala classes in typescript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/collection.ts CHANGED
@@ -293,7 +293,7 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
293
293
  return new ArrayBuffer<any>([]);
294
294
  }
295
295
 
296
- constructor(protected readonly items: T[]) {
296
+ constructor(protected readonly items: T[] = []) {
297
297
  super();
298
298
  }
299
299
 
@@ -323,6 +323,9 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
323
323
  }
324
324
  }
325
325
 
326
+ private normalized(n: number): number {
327
+ return Math.min(Math.max(n, 0), this.length);
328
+ }
326
329
 
327
330
 
328
331
  /** Replaces element at given index with a new value.
@@ -477,6 +480,53 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
477
480
  return this;
478
481
  }
479
482
 
483
+
484
+ filterInPlace(p: (element: T) => boolean): this {
485
+ let i = 0, j = 0;
486
+ while (i < this.size) {
487
+ if (p(this.items[i])) {
488
+ if (i != j) {
489
+ this.items[j] = this.items[i];
490
+ }
491
+ j += 1;
492
+ }
493
+ i += 1;
494
+ }
495
+
496
+ if (i == j) {
497
+ return this;
498
+ } else {
499
+ return this.takeInPlace(j);
500
+ }
501
+
502
+ }
503
+
504
+ dropInPlace(n: number): this {
505
+ this.remove(0, this.normalized(n));
506
+ return this;
507
+ }
508
+
509
+ dropRightInPlace(n: number): this {
510
+ const norm = this.normalized(n);
511
+ this.remove(this.length - norm, norm);
512
+ return this;
513
+ }
514
+
515
+ takeInPlace(n: number): this {
516
+ const norm = this.normalized(n);
517
+ this.remove(norm, this.length - norm);
518
+ return this;
519
+ }
520
+
521
+ takeRightInPlace(n: number): this {
522
+ this.remove(0, this.length - this.normalized(n));
523
+ return this;
524
+ }
525
+
526
+ sliceInPlace(start: number, end: number): this {
527
+ return this.takeInPlace(end).dropInPlace(start);
528
+ }
529
+
480
530
  get toCollection(): Collection<T> {
481
531
  return new Collection<T>(this.items.slice(0));
482
532
  }
@@ -500,9 +550,10 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
500
550
  * `f` to each element of this $coll and concatenating the results.
501
551
  */
502
552
  flatMap<B>(f: (item: T) => ArrayBuffer<B>): ArrayBuffer<B> {
503
- const res: B[] = [];
553
+ //https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
554
+ let res: B[] = [];
504
555
  this.items.forEach(i => {
505
- res.push(...f(i).items);
556
+ res = res.concat(...f(i).items);
506
557
  });
507
558
  return new ArrayBuffer<B>(res);
508
559
  }
@@ -519,10 +570,11 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
519
570
 
520
571
 
521
572
  async flatMapPromise<B>(f: (item: T) => Promise<ArrayBuffer<B>>): Promise<ArrayBuffer<B>> {
522
- const res: B[] = [];
573
+ //https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
574
+ let res: B[] = [];
523
575
  for (let i = 0; i < this.items.length; i++) {
524
576
  const item = this.items[i];
525
- res.push(...(await f(item)).items);
577
+ res = res.concat((await f(item)).items);
526
578
  }
527
579
  return new ArrayBuffer<B>(res);
528
580
  }