Skip to content

Commit

Permalink
improving repeat operator
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Aug 3, 2024
1 parent ad62a4e commit 8d89bc9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ops/repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ function repeatSync<T>(
state: IterationState
) => boolean)
): Iterable<T> {
if (typeof count === 'number' && count < 1) {
return iterable;
}
return {
[$S](): Iterator<T> {
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,
Expand Down Expand Up @@ -120,12 +123,15 @@ function repeatAsync<T>(
state: IterationState
) => boolean | Promise<boolean>)
): AsyncIterable<T> {
if (typeof count === 'number' && count < 1) {
return iterable;
}
return {
[$A](): AsyncIterator<T> {
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,
Expand Down

0 comments on commit 8d89bc9

Please sign in to comment.