// ets_tracing: off import { identity, pipe } from "../Function/index.js" import * as O from "../Option/index.js" import { catchAll_ } from "./catchAll.js" import { die } from "./die.js" import type { Effect } from "./effect.js" import { fail } from "./fail.js" /** * Keeps some of the errors, and terminates the fiber with the rest, using * the specified function to convert the `E` into a `Throwable`. * * @ets_data_first refineOrDieWith_ */ export function refineOrDieWith( pf: (e: E) => O.Option, f: (e: E) => unknown, __trace?: string ) { return (self: Effect) => refineOrDieWith_(self, pf, f, __trace) } /** * Keeps some of the errors, and terminates the fiber with the rest, using * the specified function to convert the `E` into a `Throwable`. */ export function refineOrDieWith_( self: Effect, pf: (e: E) => O.Option, f: (e: E) => unknown, __trace?: string ) { return catchAll_( self, (e) => pipe( e, pf, O.fold( () => die(f(e)), (e1) => fail(e1) ) ), __trace ) } /** * Keeps some of the errors, and terminates the fiber with the rest * * @ets_data_first refineOrDie_ */ export function refineOrDie(pf: (e: E) => O.Option, __trace?: string) { return (self: Effect) => refineOrDie_(self, pf, __trace) } /** * Keeps some of the errors, and terminates the fiber with the rest */ export function refineOrDie_( self: Effect, pf: (e: E) => O.Option, __trace?: string ) { return refineOrDieWith_(self, pf, identity, __trace) }