Skip to main content
Module

x/aitertools/mod.ts>drop

Well-tested utility functions dealing with async iterables
Go to Latest
function drop
import { drop } from "https://deno.land/x/aitertools@0.5.0/mod.ts";

Drops a specified number of elements from the beginning of an async iterable, and yields the remaining elements.

import { drop } from "./drop.ts";

async function* gen() { yield "foo"; yield "bar"; yield "baz"; yield "qux" }
const iterable = drop(gen(), 2);
for await (const value of iterable) {
  console.log(value);
}

The above example will print the following 2 lines:

baz
qux

If the iterable is shorter than or equal to the specified number, no elements are yielded.

import { drop } from "./drop.ts";

async function* gen() { yield "foo"; yield "bar"; yield "baz"; yield "qux" }
const iterable = drop(gen(), 4);
for await (const value of iterable) {
  console.log(value);
}

The above example will print nothing.

Type Parameters

T

The type of the elements in the source and the returned async iterable.

Parameters

source: Iterable<T> | AsyncIterable<T>

The async iterable to drop elements from. It can be either finite or infinite.

count: number

The number of elements to drop.

Returns

AsyncIterableIterator<T>

An async iterable that yields the remaining elements after dropping the first count elements from the source iterable.