// ets_tracing: off import { chain_, succeed, yieldNow } from "./core.js" import type { Effect } from "./effect.js" import { zipRight_ } from "./zips.js" /** * Repeats this effect until its error satisfies the specified effectful predicate. * * @ets_data_first repeatUntilM_ */ export function repeatUntilM( f: (a: A) => Effect, __trace?: string ) { return (self: Effect): Effect => repeatUntilM_(self, f) } /** * Repeats this effect until its error satisfies the specified effectful predicate. */ export function repeatUntilM_( self: Effect, f: (a: A) => Effect, __trace?: string ): Effect { return chain_( self, (a) => chain_(f(a), (b) => b ? succeed(a) : zipRight_(yieldNow, repeatUntilM_(self, f)) ), __trace ) } /** * Repeats this effect until its error satisfies the specified predicate. * * @ets_data_first repeatUntil_ */ export function repeatUntil(f: (a: A) => boolean, __trace?: string) { return (self: Effect) => repeatUntil_(self, f, __trace) } /** * Repeats this effect until its error satisfies the specified predicate. */ export function repeatUntil_( self: Effect, f: (a: A) => boolean, __trace?: string ) { return repeatUntilM_(self, (a) => succeed(f(a)), __trace) }