// tracing: off
import * as C from "../Cause"
import { identity, pipe } from "../Function"
import * as O from "../Option/core"
import { catchAllCause_ } from "./catchAllCause"
import { halt } from "./core"
import { fail } from "./fail"
/**
 * Takes some fiber failures and converts them into errors.
 *
 * @dataFirst unrefine_
 */

export function unrefine(pf, __trace) {
  return (fa) => unrefine_(fa, pf, __trace)
}
/**
 * Takes some fiber failures and converts them into errors.
 */

export function unrefine_(fa, pf, __trace) {
  return unrefineWith_(fa, pf, identity, __trace)
}
/**
 * Takes some fiber failures and converts them into errors, using the
 * specified function to convert the `E` into an `E1 | E2`.
 *
 * @dataFirst unrefineWith_
 */

export function unrefineWith(pf, f, __trace) {
  return (fa) => unrefineWith_(fa, pf, f, __trace)
}
/**
 * Takes some fiber failures and converts them into errors, using the
 * specified function to convert the `E` into an `E1 | E2`.
 */

export function unrefineWith_(fa, pf, f, __trace) {
  return catchAllCause_(
    fa,
    (cause) =>
      O.fold_(
        C.find((c) => (c._tag === "Die" ? pf(c.value) : O.none))(cause),
        () => halt(C.map(f)(cause)),
        fail
      ),
    __trace
  )
}
//# sourceMappingURL=unrefine.js.map
