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

x/rimbu/common/reducer.ts>Reducer.count

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

Returns a Reducer that remembers the amount of input items provided.

Examples

Example 1

const stream = Stream.range({ amount: 10 })
console.log(stream.reduce(Reducer.count()))
// => 10
console.log(stream.reduce(Reducer.count(v => v < 5)))
// => 5

type

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