takeEnd<T>(source: Iterable<T> | AsyncIterable<T>,count: number,): AsyncIterableIterator<T>
Takes a specified number of elements from the end of an async iterable.
import { takeEnd } from "./take.ts"; import { range } from "./range.ts"; const iterable = takeEnd(range(10), 3); for await (const value of iterable) console.log(value);
The above example will print the following 3 lines:
7 8 9
If the iterable is shorter than the specified number, the whole elements are taken.
import { takeEnd } from "./take.ts"; async function* gen() { yield "foo"; yield "bar"; yield "baz"; } const iterable = takeEnd(gen(), 5); for await (const value of iterable) console.log(value);
The above example will print only 3 elements, because gen() yields only 3
elements:
foo bar baz
AsyncIterableIterator<T>
An async iterable that yields the last count elements
from the source iterable.