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

x/rimbu/common/async-reducer.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@1.0.5/common/async-reducer.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>; }