MCPcopy Create free account
hub / github.com/Effect-TS/effect / StreamRechunker

Class StreamRechunker

packages/effect/src/internal/stream.ts:5155–5186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5153 })
5154
5155class StreamRechunker<out A, in out E> {
5156 private builder: Array<A> = []
5157 private pos = 0
5158
5159 constructor(readonly n: number) {
5160 }
5161
5162 isEmpty(): boolean {
5163 return this.pos === 0
5164 }
5165
5166 write(elem: A): Chunk.Chunk<A> | undefined {
5167 this.builder.push(elem)
5168 this.pos += 1
5169
5170 if (this.pos === this.n) {
5171 const result = Chunk.unsafeFromArray(this.builder)
5172 this.builder = []
5173 this.pos = 0
5174 return result
5175 }
5176
5177 return undefined
5178 }
5179
5180 emitIfNotEmpty(): Channel.Channel<Chunk.Chunk<A>, unknown, E, E, void, unknown> {
5181 if (this.pos !== 0) {
5182 return core.write(Chunk.unsafeFromArray(this.builder))
5183 }
5184 return core.void
5185 }
5186}
5187
5188/** @internal */
5189export const refineOrDie = dual<

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected