Skip to content

Commit 1dd9fe9

Browse files
committed
del: remove batched iterator
1 parent 30d2c50 commit 1dd9fe9

File tree

2 files changed

+0
-64
lines changed

2 files changed

+0
-64
lines changed

packages/core/src/shared/utilities/asyncCollection.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ export interface AsyncCollection<T> extends AsyncIterable<T> {
6161
* Returns an iterator directly from the underlying generator, preserving values returned.
6262
*/
6363
iterator(): AsyncIterator<T, T | void>
64-
65-
/**
66-
* Returns a batched iterator of any size directly from the underlying generator, preserving values returned.
67-
*/
68-
batchedIterator(batchSize: number): AsyncIterator<T[], void | T[]>
6964
}
7065

7166
const asyncCollection = Symbol('asyncCollection')
@@ -108,38 +103,9 @@ export function toCollection<T>(generator: () => AsyncGenerator<T, T | undefined
108103
toMap: <U extends string = never, K extends StringProperty<T> = never>(selector: KeySelector<T, U> | K) =>
109104
asyncIterableToMap(iterable, selector),
110105
iterator: generator,
111-
batchedIterator: (batchSize: number) => batchIterator(batchSize, filterGenerator(generator(), Boolean)),
112106
})
113107
}
114108

115-
/**
116-
* Transform an iterator to return batches of size 'batchSize'.
117-
* @param batchSize
118-
* @param iterator
119-
*/
120-
export async function* batchIterator<T>(
121-
batchSize: number,
122-
iterator: AsyncIterator<T, void | T>
123-
): AsyncIterator<T[], void | T[]> {
124-
let batch: T[] = []
125-
let nextResult = await iterator.next()
126-
127-
while (!nextResult.done) {
128-
batch.push(nextResult.value)
129-
130-
if (batch.length === batchSize) {
131-
yield batch
132-
batch = []
133-
}
134-
135-
nextResult = await iterator.next()
136-
}
137-
138-
if (batch.length > 0) {
139-
yield batch
140-
}
141-
}
142-
143109
export function isAsyncCollection<T>(iterable: AsyncIterable<T>): iterable is AsyncCollection<T> {
144110
return asyncCollection in iterable
145111
}

packages/core/src/test/shared/utilities/asyncCollection.test.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import assert from 'assert'
77
import { toCollection } from '../../../shared/utilities/asyncCollection'
8-
import { intoCollection } from '../../../shared/utilities/collectionUtils'
98

109
describe('AsyncCollection', function () {
1110
const items = [
@@ -206,35 +205,6 @@ describe('AsyncCollection', function () {
206205
assert.strictEqual(counter.callCount, 7)
207206
})
208207

209-
describe('batchedIterator', function () {
210-
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9]
211-
const mixedItems = [1, '2', 3, '4', 5, '6']
212-
213-
it('can iterator batches at a time', async function () {
214-
const batchedIterator = intoCollection(items).batchedIterator(3)
215-
assert.deepStrictEqual((await batchedIterator.next()).value, [1, 2, 3], 'first batch')
216-
assert.deepStrictEqual((await batchedIterator.next()).value, [4, 5, 6], 'second batch')
217-
assert.deepStrictEqual((await batchedIterator.next()).value, [7, 8, 9], 'third batch')
218-
assert.ok((await batchedIterator.next()).done)
219-
})
220-
221-
it('can handle partial batches', async function () {
222-
const batchedIterator = intoCollection(items).batchedIterator(4)
223-
assert.deepStrictEqual((await batchedIterator.next()).value, [1, 2, 3, 4], 'first batch')
224-
assert.deepStrictEqual((await batchedIterator.next()).value, [5, 6, 7, 8], 'second batch')
225-
assert.deepStrictEqual((await batchedIterator.next()).value, [9], 'third batch')
226-
assert.ok((await batchedIterator.next()).done)
227-
})
228-
229-
it('can handle mixed valued batches', async function () {
230-
const batchedIterator = intoCollection(mixedItems).batchedIterator(2)
231-
assert.deepStrictEqual((await batchedIterator.next()).value, [1, '2'], 'first batch')
232-
assert.deepStrictEqual((await batchedIterator.next()).value, [3, '4'], 'second batch')
233-
assert.deepStrictEqual((await batchedIterator.next()).value, [5, '6'], 'third batch')
234-
assert.ok((await batchedIterator.next()).done)
235-
})
236-
})
237-
238208
describe('errors', function () {
239209
async function* error() {
240210
throw new Error()

0 commit comments

Comments
 (0)