Skip to main content

type window

Returns an async transformer that produces windows/collections of windowSize size, each window starting skipAmount of elements after the previous, and optionally collected by a custom reducer.

example
await AsyncStream.of(1, 2, 3, 4, 5, 6)
.transform(AsyncTransformer.window(3))
.toArray()
// => [[1, 2, 3], [4, 5, 6]]

Definition

window: {
    <T, R>(windowSize: number, options: {
      skipAmount?: number | undefined;
      collector: AsyncReducer.Accept<T, R>;
    }): AsyncTransformer<T, R>;
    <T>(windowSize: number, options?: {
      skipAmount?: number | undefined;
      collector?: undefined;
    }): AsyncTransformer<T, T[]>;
  }