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

x/rimbu/core/main/index.ts>Reducer.firstWhere

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

Returns a Reducer that remembers the first input value for which the given pred function returns true.

Examples

Example 1

console.log(Stream.range({ amount: 10 }).reduce(Reducer.firstWhere(v => v > 5)))
// => 6

type

{ <T>(pred: (value: T, index: number) => boolean): Reducer<T, T | undefined>; <T, O>(pred: (value: T, index: number) => boolean, otherwise: OptLazy<O>): Reducer<T, T | O>; }