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,