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

Syntax

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

takeIter<T>(
  iterable: Iterable<T>,
  n: number = 1
): Generator<T>;

Parameters

  • iterable: The source iterable.

  • n: The number of elements to take. Default: 1.

Returns

A Generator that yields the specified number of elements.

Examples

TypeScript
const arr = [1, 2, 3, 4];
const iter = takeIter(arr, 2);
[...iter]; //=> [1, 2]
Last updated on
Edit this page