🧩 Returns the nth item (0-indexed) from an async iterable.
Syntax
TypeScript
import { nthIterAsync } from '@opentf/std'; nthIterAsync<T>(iter: AsyncIterable<T>, n: number): Promise<T | undefined>
Parameters
iter: The async iterable to search.n: The index of the item to return.
Returns
A promise that resolves to the nth item, or undefined.
Examples
TypeScript
async function* gen() { yield 1; yield 2; } await nthIterAsync(gen(), 1) //=> 2