import * as tsplus_module_1 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/fromEffect";
import * as tsplus_module_3 from "@effect/core/stream/Channel/operations/flatMap";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/zipRight";
import * as tsplus_module_5 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/succeed";
import * as tsplus_module_7 from "@effect/core/stream/Channel/operations/readWith";
import * as tsplus_module_8 from "@effect/core/stream/Channel/operations/pipeToOrFail";
import { concreteSink, SinkInternal } from "@effect/core/stream/Sink/operations/_internal/SinkInternal";
/**
 * Effectfully transforms this sink's input chunks. `f` must preserve
 * chunking-invariance.
 *
 * @tsplus fluent ets/Sink contramapChunksEffect
 */

export function contramapChunksEffect_(self, f, __tsplusTrace) {
  const loop = tsplus_module_7.readWith(chunk => tsplus_module_4.zipRight_(tsplus_module_3.flatMap_(tsplus_module_2.fromEffect(() => f(chunk)), chunk => tsplus_module_1.write(() => chunk)), () => loop), err => tsplus_module_5.fail(() => err), done => tsplus_module_6.succeed(() => done));
  void 0;
  return new SinkInternal(tsplus_module_8.pipeToOrFail_(loop, () => self.channel));
}
/**
 * Effectfully transforms this sink's input chunks. `f` must preserve
 * chunking-invariance.
 *
 * @tsplus static ets/Sink/Aspects contramapChunksEffect
 */

export const contramapChunksEffect = (f, __tsplusTrace) => self => contramapChunksEffect_(self, f, __tsplusTrace);
//# sourceMappingURL=contramapChunksEffect.mjs.map