Skip to main content
Module

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