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

x/rimbu/common/index.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.13.0/common/index.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>; }