MCPcopy
hub / github.com/Effect-TS/effect / SingleShotGen

Class SingleShotGen

packages/effect/src/Utils.ts:109–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107 * @since 2.0.0
108 */
109export 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected