UNPKG

asyncerator

Version:

Provide supporting types for AsyncIterable/AsyncIterableIterators, promisified stream.pipeline implementation, and Array-like utility operators, sources and sinks.

27 lines (22 loc) 605 B
// operator/skip.ts /* * Copyright (c) 2021-2024 Check Digit, LLC * * This code is licensed under the MIT license (see LICENSE.txt for details). */ import type { Asyncerator } from '../asyncerator'; import type { Operator } from './index'; /** * Skip numberToSkip values at the start of a stream. * @param numberToSkip */ export default function <Input>(numberToSkip = 1): Operator<Input, Input> { return async function* (iterator: Asyncerator<Input>) { let count = 0; for await (const item of iterator) { if (count++ >= numberToSkip) { yield item; } } }; }