🧩 Finds the first item in an async iterator that matches a predicate.
Syntax
TypeScript
import { findIterAsync } from '@opentf/std'; findIterAsync<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 first matching item, or undefined.
Examples
TypeScript
async function* gen() { yield 1; yield 2; } await findIterAsync(gen(), x => x > 1) //=> 2