Represents a batch of items.
for of
import { Batch } from '../src/index.js';console.log(Array.from(Batch.from([1, 2, 3, 4, 5], 3))); Copy
import { Batch } from '../src/index.js';console.log(Array.from(Batch.from([1, 2, 3, 4, 5], 3)));
for await of
import { Batch } from '../src/index.js';async function* getSource() { for (let i = 0; i < 5; i++) { await new Promise((resolve) => setTimeout(resolve)); yield i; }}console.log(await Array.fromAsync(Batch.fromAsync(getSource(), 3))); Copy
import { Batch } from '../src/index.js';async function* getSource() { for (let i = 0; i < 5; i++) { await new Promise((resolve) => setTimeout(resolve)); yield i; }}console.log(await Array.fromAsync(Batch.fromAsync(getSource(), 3)));
Predicate:
import { Batch } from '../src/index.js';console.log(Array.from(Batch.from([1, 2, 3, 4, 5], 2, (v) => v % 2 === 0))); Copy
import { Batch } from '../src/index.js';console.log(Array.from(Batch.from([1, 2, 3, 4, 5], 2, (v) => v % 2 === 0)));
Chaining:
import { Batch } from '../src/index.js';Batch.from([1, 2, 3, 4, 5], 3).forEach((batch) => { console.log(batch);}); Copy
import { Batch } from '../src/index.js';Batch.from([1, 2, 3, 4, 5], 3).forEach((batch) => { console.log(batch);});
Represents a batch of items.
for of
for await of
Predicate:
Chaining: