// ets_tracing: off import { pipe } from "../Function/index.js" import * as O from "../Option/index.js" import * as catchAll from "./catchAll.js" import type { Effect } from "./effect.js" import { fail } from "./fail.js" /** * Returns an effect that will produce the value of this effect, unless it * fails with the `None` value, in which case it will produce the value of * the specified effect. * * @ets_data_first orElseOptional_ */ export function orElseOptional( that: () => Effect, A2>, __trace?: string ) { return (self: Effect, A>) => orElseOptional_(self, that, __trace) } /** * Returns an effect that will produce the value of this effect, unless it * fails with the `None` value, in which case it will produce the value of * the specified effect. */ export function orElseOptional_( self: Effect, A>, that: () => Effect, A2>, __trace?: string ): Effect, A | A2> { return pipe( self, catchAll.catchAll, O.Option, A2>( O.fold(that, (x) => pipe(x, O.some, fail)), __trace ) ) }