// ets_tracing: off import { pipe } from "../Function/index.js" import * as O from "../Option/core.js" import { chain_, succeed } from "./core.js" import type { Effect } from "./effect.js" import { failWith } from "./fail.js" /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * continue with the returned value. */ export function continueOrFailM_( fa: Effect, f: () => E1, pf: (a: A) => O.Option>, __trace?: string ) { return chain_( fa, (a): Effect => pipe( pf(a), O.getOrElse(() => failWith(f)) ), __trace ) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * continue with the returned value. * * @ets_data_first continueOrFailM_ */ export function continueOrFailM( f: () => E1, pf: (a: A) => O.Option>, __trace?: string ) { return (fa: Effect) => continueOrFailM_(fa, f, pf, __trace) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. */ export function continueOrFail_( fa: Effect, f: () => E1, pf: (a: A) => O.Option, __trace?: string ) { return continueOrFailM_(fa, f, (x) => pipe(x, pf, O.map(succeed)), __trace) } /** * Fail with `e` if the supplied `PartialFunction` does not match, otherwise * succeed with the returned value. * * @ets_data_first continueOrFail_ */ export function continueOrFail( f: () => E1, pf: (a: A) => O.Option, __trace?: string ) { return (fa: Effect) => continueOrFail_(fa, f, pf, __trace) }