import { concreteSink, SinkInternal } from "@effect/core/stream/Sink/operations/_internal/SinkInternal" /** * Transforms this sink's input chunks. `f` must preserve chunking-invariance. * * @tsplus static effect/core/stream/Sink.Aspects contramapChunks * @tsplus pipeable effect/core/stream/Sink contramapChunks */ export function contramapChunks( f: (input: Chunk) => Chunk ) { return (self: Sink): Sink => { const loop: Channel< R, never, Chunk, unknown, never, Chunk, unknown > = Channel.readWith( (chunk: Chunk) => Channel.write(f(chunk)).flatMap(() => loop), (err) => Channel.fail(err), (done) => Channel.succeed(done) ) concreteSink(self) return new SinkInternal(loop >> self.channel) } }