// tracing: off
import * as E from "../Either"
import { NoSuchElementException } from "../GlobalExceptions"
import * as O from "../Option"
import { chain_, succeed } from "./core"
import { fail, failWith } from "./fail"
import { foldM_ } from "./foldM"
/**
 * Returns a successful effect if the value is `Left`, or fails with the error e.
 */

export function leftOrFail_(self, orFail, __trace) {
  return chain_(
    self,
    E.fold(succeed, (x) => failWith(() => orFail(x))),
    __trace
  )
}
/**
 * Returns a successful effect if the value is `Left`, or fails with the error e.
 *
 * @dataFirst leftOrFail_
 */

export function leftOrFail(orFail, __trace) {
  return (self) => leftOrFail_(self, orFail, __trace)
}
/**
 * Returns a successful effect if the value is `Left`, or fails with a `NoSuchElementException`.
 */

export function leftOrFailException(self, __trace) {
  return leftOrFail_(self, () => new NoSuchElementException(), __trace)
}
/**
 * Returns a successful effect if the value is `Left`, or fails with the error `None`.
 */

export function left(self) {
  return foldM_(
    self,
    (e) => fail(O.some(e)),
    E.fold(succeed, () => fail(O.none))
  )
}
//# sourceMappingURL=leftOrFail.js.map
