🧩 Returns the last item from an async iterable.

Syntax

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

lastIterAsync<T>(iter: AsyncIterable<T>): Promise<T | undefined>

Parameters

  • iter: The async iterable to search.

Returns

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

Examples

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