diff --git a/src/patterns.ts b/src/patterns.ts index 9da71283..fa11bd59 100644 --- a/src/patterns.ts +++ b/src/patterns.ts @@ -128,10 +128,18 @@ function chainable>( const variadic = (pattern: pattern): Variadic => Object.assign(pattern, { - *[Symbol.iterator]() { - yield Object.assign(pattern, { + [Symbol.iterator](): Iterator { + let i = 0; + const variadicPattern = Object.assign(pattern, { [symbols.isVariadic]: true, }); + const values: IteratorResult[] = [ + { value: variadicPattern, done: false }, + { done: true, value: undefined }, + ]; + return { + next: () => values[i++] ?? values.at(-1)!, + }; }, });