Skip to main content
Module

x/rimbu/mod.ts>AsyncReducer.count

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

Returns an AsyncReducer that remembers the amount of input items provided.

Examples

Example 1

const stream = AsyncStream.from(Stream.range({ amount: 10 }))
console.log(await stream.reduce(AsyncReducer.count()))
// => 10
console.log(await stream.reduce(AsyncReducer.count(async v => v < 5)))
// => 5

type

{ (): AsyncReducer<never, number>; <T>(pred: (value: T, index: number) => MaybePromise<boolean>): AsyncReducer<T, number>; }