import type { Bool, Fn, Prom } from '@wollybeard/kit' import { Undefined } from '@wollybeard/kit' export const until = ( predicate: Bool.Predicate, ) => (fns: fn[]): Fn.ReturnExtract => { // @ts-expect-error return async (...args) => { for (const fn of fns) { const result: any = await fn(...args) if (predicate(result)) return result } return undefined } } export const untilDefined = until(Undefined.isnt)