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

x/rimbu/common/index.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@0.13.0/common/index.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): Reducer<T, T | undefined>; <T, O>(pred: (value: T, index: number) => boolean, otherwise: OptLazy<O>): Reducer<T, T | O>; }