| 107 | * @since 2.0.0 |
| 108 | */ |
| 109 | export class SingleShotGen<T, A> implements IterableIterator<T, A> { |
| 110 | private called = false |
| 111 | |
| 112 | constructor(readonly self: T) {} |
| 113 | |
| 114 | /** |
| 115 | * @since 2.0.0 |
| 116 | */ |
| 117 | next(a: A): IteratorResult<T, A> { |
| 118 | return this.called ? |
| 119 | ({ |
| 120 | value: a, |
| 121 | done: true |
| 122 | }) : |
| 123 | (this.called = true, |
| 124 | ({ |
| 125 | value: this.self, |
| 126 | done: false |
| 127 | })) |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @since 2.0.0 |
| 132 | */ |
| 133 | return(a: A): IteratorResult<T, A> { |
| 134 | return ({ |
| 135 | value: a, |
| 136 | done: true |
| 137 | }) |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @since 2.0.0 |
| 142 | */ |
| 143 | throw(e: unknown): IteratorResult<T, A> { |
| 144 | throw e |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @since 2.0.0 |
| 149 | */ |
| 150 | [Symbol.iterator](): IterableIterator<T, A> { |
| 151 | return new SingleShotGen<T, A>(this.self) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @category constructors |
nothing calls this directly
no outgoing calls
no test coverage detected