import * as tsplus_module_1 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/zipRight";
import * as tsplus_module_3 from "@effect/core/io/Cause/errors";
import * as tsplus_module_4 from "@effect/core/io/Cause/definition";
import * as tsplus_module_5 from "@effect/core/stream/Channel/operations/failCause";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/succeedNow";
import * as tsplus_module_7 from "@effect/core/stream/Channel/operations/readWith";
import * as tsplus_module_8 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_9 from "@effect/core/stream/Channel/operations/readWithCause";
import * as tsplus_module_10 from "@effect/core/stream/Channel/operations/pipeTo";
import { isChannelError } from "@effect/core/io/Cause/errors";
/**
 * @tsplus fluent ets/Channel pipeToOrFail
 */

export function pipeToOrFail_(self, that) {
  const reader = tsplus_module_7.readWith(outElem => tsplus_module_2.zipRight_(tsplus_module_1.write(() => outElem), () => reader), outErr => tsplus_module_5.failCause(() => tsplus_module_4.die(new tsplus_module_3.ChannelError(outErr))), outDone => tsplus_module_6.succeedNow(outDone));
  const writer = tsplus_module_9.readWithCause(outElem => tsplus_module_2.zipRight_(tsplus_module_1.write(() => outElem), () => writer), cause => tsplus_module_4.isDieType(cause) && isChannelError(cause.value) ? tsplus_module_8.fail(() => cause.value.error) : tsplus_module_5.failCause(() => cause), outDone => tsplus_module_6.succeedNow(outDone));
  return tsplus_module_10.pipeTo_(tsplus_module_10.pipeTo_(tsplus_module_10.pipeTo_(self, () => reader), () => that()), () => writer);
}
/**
 * @tsplus static ets/Channel/Aspects pipeToOrFail
 */

export const pipeToOrFail = that => self => pipeToOrFail_(self, that);
//# sourceMappingURL=pipeToOrFail.mjs.map