From 8d89bc939b15d51536aab967a947e9d43dd86395 Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Sat, 3 Aug 2024 20:55:05 +0100 Subject: [PATCH] improving repeat operator --- src/ops/repeat.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ops/repeat.ts b/src/ops/repeat.ts index dd53e97b..0c32251d 100644 --- a/src/ops/repeat.ts +++ b/src/ops/repeat.ts @@ -70,12 +70,15 @@ function repeatSync( state: IterationState ) => boolean) ): Iterable { + if (typeof count === 'number' && count < 1) { + return iterable; + } return { [$S](): Iterator { const i = iterable[$S](); const state: IterationState = {}; const cb = typeof count === 'function' && count; - const initialCount = !cb && count > 0 ? count : 0; + const initialCount = !cb && count; let copyCount = initialCount; let index = -1, copied = 0, @@ -120,12 +123,15 @@ function repeatAsync( state: IterationState ) => boolean | Promise) ): AsyncIterable { + if (typeof count === 'number' && count < 1) { + return iterable; + } return { [$A](): AsyncIterator { const i = iterable[$A](); const state: IterationState = {}; const cb = typeof count === 'function' && count; - const initialCount = !cb && count > 0 ? count : 0; + const initialCount = !cb && count; let copyCount = initialCount; let index = -1, copied = 0,