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

x/rimbu/core/mod.ts>AsyncReducer.lastWhere

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

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

Examples

Example 1

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

type

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

Examples

Example 1

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

type

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