method Stream.chunks
Stream.chunks(size: number): Stream<T[], E>

Collects consecutive successful values into fixed-size arrays. Errors pass through without breaking the current chunk.

Examples

Example 1

import { Source } from "anabranch";

const stream = Source.from<number, Error>(async function* () {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
  yield 5;
});

const chunked = stream.chunks(2);
// Emits: { type: "success", value: [1, 2] }, { type: "success", value: [3, 4] }, { type: "success", value: [5] }

Parameters

size: number

Return Type

Stream<T[], E>

Usage

import { type Stream } from ".";