🧩 Finds the index of the first item in an async iterator that matches a predicate.

Syntax

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

findIndexIterAsync<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 first matching item, or -1.

Examples

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