/** * Returns a new effect that repeats this effect the specified number of times * or until the first failure. Repeats are in addition to the first execution, * so that `io.repeatN(1)` yields an effect that executes `io`, and then if * that succeeds, executes `io` an additional time. * * @tsplus static effect/core/io/Effect.Aspects repeatN * @tsplus pipeable effect/core/io/Effect repeatN */ export function repeatN(n: number) { return (self: Effect): Effect => Effect.suspendSucceed(loop(self, n)) } function loop(self: Effect, n: number): Effect { return self.flatMap((a) => n <= 0 ? Effect.succeed(a) : Effect.yieldNow.zipRight(loop(self, n - 1)) ) }