// ets_tracing: off import { chain_, succeedWith, suspend } from "./core.js" import type { Effect, RIO } from "./effect.js" import { fail } from "./fail.js" /** * Evaluate the predicate, * return the given A as success if predicate returns true, * and the given E as error otherwise * * @ets_data_first cond_ */ export function cond(onTrue: () => A, onFalse: () => E, __trace?: string) { return (b: boolean): Effect => cond_(b, onTrue, onFalse, __trace) } /** * Evaluate the predicate, * return the given A as success if predicate returns true, * and the given E as error otherwise */ export function cond_( b: boolean, onTrue: () => A, onFalse: () => E, __trace?: string ): Effect { return condM_(b, succeedWith(onTrue), succeedWith(onFalse), __trace) } /** * Evaluate the predicate, * return the given A as success if predicate returns true, * and the given E as error otherwise */ export function condM_( b: boolean, onTrue: RIO, onFalse: RIO, __trace?: string ): Effect { return suspend( (): Effect => (b ? onTrue : chain_(onFalse, (x) => fail(x))), __trace ) } /** * Evaluate the predicate, * return the given A as success if predicate returns true, * and the given E as error otherwise */ export function condM( onTrue: RIO, onFalse: RIO, __trace?: string ): (b: boolean) => Effect { return (b) => condM_(b, onTrue, onFalse, __trace) }