Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/core/mod.ts>AsyncTransformer.window

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
variable AsyncTransformer.window
import { AsyncTransformer } from "https://deno.land/x/rimbu@1.2.0/core/mod.ts";
const { window } = AsyncTransformer;

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.

Examples

Example 1

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

type

{ <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[]>; }

Examples

Example 1

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

type

{ <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[]>; }