🧩 Finds the last item in an async iterator that matches a predicate.

Syntax

TypeScript
import { findLastIterAsync } from '@opentf/std';

findLastIterAsync<T>(iter: AsyncIterable<T>, fn: (val: T) => boolean | Promise<boolean>): Promise<T | undefined>

Parameters

  • iter: The async iterable to search.

  • fn: The predicate function.

Returns

A promise that resolves to the last matching item, or undefined.

Examples

TypeScript
async function* gen() { yield 1; yield 2; yield 3; }
await findLastIterAsync(gen(), x => x < 3) //=> 2
Last updated on
Edit this page