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

Class StreamRechunker

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

Source from the content-addressed store, hash-verified

5115 })
5116
5117class StreamRechunker<out A, in out E> {
5118 private builder: Array<A> = []
5119 private pos = 0
5120
5121 constructor(readonly n: number) {
5122 }
5123
5124 isEmpty(): boolean {
5125 return this.pos === 0
5126 }
5127
5128 write(elem: A): Chunk.Chunk<A> | undefined {
5129 this.builder.push(elem)
5130 this.pos += 1
5131
5132 if (this.pos === this.n) {
5133 const result = Chunk.unsafeFromArray(this.builder)
5134 this.builder = []
5135 this.pos = 0
5136 return result
5137 }
5138
5139 return undefined
5140 }
5141
5142 emitIfNotEmpty(): Channel.Channel<Chunk.Chunk<A>, unknown, E, E, void, unknown> {
5143 if (this.pos !== 0) {
5144 return core.write(Chunk.unsafeFromArray(this.builder))
5145 }
5146 return core.void
5147 }
5148}
5149
5150/** @internal */
5151export const refineOrDie = dual<

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…