// tracing: off
import * as O from "../Option"
import { succeed } from "./core"
import { fail } from "./fail"
import { foldM_ } from "./foldM"
/**
 * Converts an option on errors into an option on values.
 */

export function optional(self, __trace) {
  return foldM_(
    self,
    O.fold(() => succeed(O.none), fail),
    (a) => succeed(O.some(a)),
    __trace
  )
}
//# sourceMappingURL=optional.js.map
