Skip to main content
Module

x/froebel/mod.ts>take

A strictly typed utility library.
Go to Latest
variable take
import { take } from "https://deno.land/x/froebel@v0.21.0/mod.ts";

Takes n elements from the iterable list and returns them as an array.

Examples

Example 1

take(5, repeat(1, 2))  // -> [1, 2, 1, 2, 1]
take(3, [1, 2, 3, 4])  // -> [1, 2, 3]
take(3, [1, 2])        // -> [1, 2]

type

<T>(n: number, list: Iterable<T>) => T[]
function take
import { take } from "https://deno.land/x/froebel@v0.21.0/mod.ts";

Takes n elements from the iterable list and returns them as a generator.

Examples

Example 1

[...take(5, repeat(1, 2))]  // -> [1, 2, 1, 2, 1]
[...take(3, [1, 2, 3, 4])]  // -> [1, 2, 3]
[...take(3, [1, 2])]        // -> [1, 2]

Parameters

n: number
list: Iterable<T>

Returns

Generator<T>