aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/UtilExtensions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/UtilExtensions.ts')
-rw-r--r--src/client/util/UtilExtensions.ts22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/client/util/UtilExtensions.ts b/src/client/util/UtilExtensions.ts
index da47fc1bc..1447e37cb 100644
--- a/src/client/util/UtilExtensions.ts
+++ b/src/client/util/UtilExtensions.ts
@@ -17,14 +17,19 @@ module.exports.BatchAsync = async function <T, A>(batcher: BatcherAsync<T, A>):
module.exports.PredicateBatch = function <T, A>(batcher: PredicateBatcher<T, A>): T[][] {
const batches: T[][] = [];
let batch: T[] = [];
- const { executor, initial } = batcher;
- let accumulator: A | undefined = initial;
+ const { executor, initial, persistAccumulator } = batcher;
+ let accumulator = initial;
for (let element of this) {
- if ((accumulator = executor(element, accumulator)) !== undefined) {
+ const { updated, makeNextBatch } = executor(element, accumulator);
+ accumulator = updated;
+ if (!makeNextBatch) {
batch.push(element);
} else {
batches.push(batch);
batch = [element];
+ if (!persistAccumulator) {
+ accumulator = initial;
+ }
}
}
batches.push(batch);
@@ -34,14 +39,19 @@ module.exports.PredicateBatch = function <T, A>(batcher: PredicateBatcher<T, A>)
module.exports.PredicateBatchAsync = async function <T, A>(batcher: PredicateBatcherAsync<T, A>): Promise<T[][]> {
const batches: T[][] = [];
let batch: T[] = [];
- const { executor, initial } = batcher;
- let accumulator: A | undefined = initial;
+ const { executor, initial, persistAccumulator } = batcher;
+ let accumulator: A = initial;
for (let element of this) {
- if ((accumulator = await executor(element, accumulator)) !== undefined) {
+ const { updated, makeNextBatch } = await executor(element, accumulator);
+ accumulator = updated;
+ if (!makeNextBatch) {
batch.push(element);
} else {
batches.push(batch);
batch = [element];
+ if (!persistAccumulator) {
+ accumulator = initial;
+ }
}
}
batches.push(batch);