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

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

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

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

Examples

Example 1

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

type

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