🏃‍♂️ Yields the first N elements of an async iterable.

Syntax

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

takeIterAsync<T>(iterable: AsyncIterable<T>, n: number): AsyncGenerator<T>

Parameters

  • iterable: The source async iterable.

  • n: The number of items to take.

Returns

A new async generator with the first n items.

Examples

TypeScript
async function* gen() { yield 1; yield 2; yield 3; }
await toArrayIterAsync(takeIterAsync(gen(), 2)) //=> [1, 2]
Last updated on
Edit this page