🧩 Finds the index of the last item in an async iterator that matches a predicate.
Syntax
TypeScript
import { findLastIndexIterAsync } from '@opentf/std'; findLastIndexIterAsync<T>(iter: AsyncIterable<T>, fn: (val: T) => boolean | Promise<boolean>): Promise<number>
Parameters
iter: The async iterable to search.fn: The predicate function.
Returns
A promise that resolves to the index of the last matching item, or -1.
Examples
TypeScript
async function* gen() { yield 1; yield 2; yield 3; } await findLastIndexIterAsync(gen(), x => x < 3) //=> 1