| 1 | /** @internal */ |
| 2 | export class SingleShotGen<T, A> implements Generator<T, A> { |
| 3 | called = false |
| 4 | |
| 5 | constructor(readonly self: T) { |
| 6 | } |
| 7 | |
| 8 | next(a: A): IteratorResult<T, A> { |
| 9 | return this.called ? |
| 10 | ({ |
| 11 | value: a, |
| 12 | done: true |
| 13 | }) : |
| 14 | (this.called = true, |
| 15 | ({ |
| 16 | value: this.self, |
| 17 | done: false |
| 18 | })) |
| 19 | } |
| 20 | |
| 21 | return(a: A): IteratorResult<T, A> { |
| 22 | return ({ |
| 23 | value: a, |
| 24 | done: true |
| 25 | }) |
| 26 | } |
| 27 | |
| 28 | throw(e: unknown): IteratorResult<T, A> { |
| 29 | throw e |
| 30 | } |
| 31 | |
| 32 | [Symbol.iterator](): Generator<T, A> { |
| 33 | return new SingleShotGen<T, A>(this.self) |
| 34 | } |
| 35 | } |
nothing calls this directly
no outgoing calls
no test coverage detected