Skip to main content
Module

x/iterators/mod.ts>slice

Iterators and related functions for Deno. Similar to Python's itertools module. Unlicensed, do what you want.
Latest
function slice
import { slice } from "https://deno.land/x/iterators@v0.2.0/mod.ts";

Take a slice of an iterable, starting from 0.

[...slice(count()], 5)
// => [0, 1, 2, 3, 4]

Take a slice of an iterable.

[...slice(count(), 5, 10)]
// => [5, 6, 7, 8, 9]

Take a slice of an iterable by steps of 2.

[...slice(count(), 10, 20, 2)]
// => [10, 12, 14, 16, 18]

Parameters

iterable: Iterable<T>
...sliceArgs: [number] | [number | null, number | null, number]

Returns

Generator<T>