"use strict"
Object.defineProperty(exports, "__esModule", { value: true })
exports.catch =
  exports.catchTag_ =
  exports.catchTag =
  exports.catch_ =
  exports.catchAll =
  exports.catchAll_ =
    void 0
// tracing: off
const core_1 = require("./core")
const fail_1 = require("./fail")
const foldM_1 = require("./foldM")
/**
 * Recovers from all errors.
 */
function catchAll_(effect, f, __trace) {
  return (0, foldM_1.foldM_)(effect, f, core_1.succeed, __trace)
}
exports.catchAll_ = catchAll_
/**
 * Recovers from all errors.
 *
 * @dataFirst catchAll_
 */
function catchAll(f, __trace) {
  return (effect) => catchAll_(effect, f, __trace)
}
exports.catchAll = catchAll
/**
 * Recovers from specified error.
 *
 * @dataFirst catch_
 */
function _catch(tag, k, f, __trace) {
  return (self) =>
    catchAll_(
      self,
      (e) => {
        if (tag in e && e[tag] === k) {
          return f(e)
        }
        return (0, fail_1.fail)(e)
      },
      __trace
    )
}
exports.catch = _catch
/**
 * Recovers from specified error.
 */
function catch_(self, tag, k, f, __trace) {
  return catchAll_(
    self,
    (e) => {
      if (tag in e && e[tag] === k) {
        return f(e)
      }
      return (0, fail_1.fail)(e)
    },
    __trace
  )
}
exports.catch_ = catch_
/**
 * Recovers from specified error.
 *
 * @dataFirst catchTag_
 */
function catchTag(k, f, __trace) {
  return (self) => catchTag_(self, k, f, __trace)
}
exports.catchTag = catchTag
/**
 * Recovers from specified error.
 */
function catchTag_(self, k, f, __trace) {
  return catchAll_(
    self,
    (e) => {
      if ("_tag" in e && e["_tag"] === k) {
        return f(e)
      }
      return (0, fail_1.fail)(e)
    },
    __trace
  )
}
exports.catchTag_ = catchTag_
//# sourceMappingURL=catchAll.js.map
