import * as tsplus_module_1 from "@effect/core/io/Cause/definition";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/failCause";
import * as tsplus_module_3 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_5 from "@effect/core/stream/Channel/operations/catchAll";
import { concreteStream, StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
/**
 * Keeps some of the errors, and terminates the fiber with the rest, using the
 * specified function to convert the `E` into a `Throwable`.
 *
 * @tsplus fluent ets/Stream refineOrDieWith
 */

export function refineOrDieWith_(self, pf, f, __tsplusTrace) {
  void 0;
  return new StreamInternal(tsplus_module_5.catchAll_(self.channel, e => tsplus_module_4.fold_(pf(e), () => tsplus_module_2.failCause(() => tsplus_module_1.die(f(e))), e2 => tsplus_module_3.fail(() => e2))));
}
/**
 * Keeps some of the errors, and terminates the fiber with the rest, using the
 * specified function to convert the `E` into a `Throwable`.
 *
 * @tsplus static ets/Stream/Aspects refineOrDieWith
 */

export const refineOrDieWith = (pf, f, __tsplusTrace) => self => refineOrDieWith_(self, pf, f, __tsplusTrace);
//# sourceMappingURL=refineOrDieWith.mjs.map