Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/iter/mod.ts>take

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function take
import { take } from "https://deno.land/x/iter@v3.2.3/mod.ts";

Returns a new iterable containing the first n items of it.

Examples

Example 1

import * as iter from "https://deno.land/x/iter/mod.ts";

const naturals = iter.create.increments(1);
const first6 = iter.take(naturals, 6);

for (const num of first6) {
  console.log(num);
}

// -> 1
// -> 2
// -> 3
// -> 4
// -> 5
// -> 6

Parameters

it: Iterable<T>
  • The iterable being taken from.
n: number
  • The number of items to take.

Returns

A new iterable of it which terminates after n items.