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

x/rimbu/core/main/exports.ts>AsyncReducer.firstWhere

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

Returns an AsyncReducer that remembers the first input value for which the given pred function returns true.

Examples

Example 1

await AsyncStream.from(Stream.range({ amount: 10 })).reduce(AsyncReducer.firstWhere(async v => v > 5)))
// => 6

type

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