Skip to content

Commit

Permalink
remove Effect.retry* variants
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jan 10, 2024
1 parent 94a154f commit 0d0dc88
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 439 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-insects-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

remove Effect.retry\* variants
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@
"editor.suggestSelection": "recentlyUsed",
"editor.wordBasedSuggestions": "matchingDocuments",
"editor.parameterHints.enabled": true,
"files.insertFinalNewline": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": false
"files.insertFinalNewline": true
}
109 changes: 0 additions & 109 deletions packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1812,17 +1812,6 @@ export const retry: {
<R, E extends E0, E0, A, R1, B>(self: Effect<R, E, A>, policy: Schedule.Schedule<R1, E0, B>): Effect<R | R1, E, A>
} = _schedule.retry_combined

/**
* Retries this effect the specified number of times.
*
* @since 2.0.0
* @category error handling
*/
export const retryN: {
(n: number): <R, E, A>(self: Effect<R, E, A>) => Effect<R, E, A>
<R, E, A>(self: Effect<R, E, A>, n: number): Effect<R, E, A>
} = _schedule.retryN_Effect

/**
* Retries with the specified schedule, until it fails, and then both the
* value produced by the schedule together with the last error are passed to
Expand All @@ -1843,54 +1832,6 @@ export const retryOrElse: {
): Effect<R | R1 | R2, E | E2, A | A2>
} = _schedule.retryOrElse_Effect

/**
* Retries this effect until its error satisfies the specified predicate.
*
* @since 2.0.0
* @category error handling
*/
export const retryUntil: {
<E, E2 extends E>(f: Refinement<E, E2>): <R, A>(self: Effect<R, E, A>) => Effect<R, E2, A>
<E>(f: Predicate<E>): <R, A>(self: Effect<R, E, A>) => Effect<R, E, A>
<R, E, A, E2 extends E>(self: Effect<R, E, A>, f: Refinement<E, E2>): Effect<R, E2, A>
<R, E, A>(self: Effect<R, E, A>, f: Predicate<E>): Effect<R, E, A>
} = _schedule.retryUntil_Effect

/**
* Retries this effect until its error satisfies the specified effectful
* predicate.
*
* @since 2.0.0
* @category error handling
*/
export const retryUntilEffect: {
<R1, E, E2>(f: (e: E) => Effect<R1, E2, boolean>): <R, A>(self: Effect<R, E, A>) => Effect<R1 | R, E | E2, A>
<R, E, A, R1, E2>(self: Effect<R, E, A>, f: (e: E) => Effect<R1, E2, boolean>): Effect<R | R1, E | E2, A>
} = _schedule.retryUntilEffect_Effect

/**
* Retries this effect while its error satisfies the specified predicate.
*
* @since 2.0.0
* @category error handling
*/
export const retryWhile: {
<E>(f: Predicate<E>): <R, A>(self: Effect<R, E, A>) => Effect<R, E, A>
<R, E, A>(self: Effect<R, E, A>, f: Predicate<E>): Effect<R, E, A>
} = _schedule.retryWhile_Effect

/**
* Retries this effect while its error satisfies the specified effectful
* predicate.
*
* @since 2.0.0
* @category error handling
*/
export const retryWhileEffect: {
<R1, E, E2>(f: (e: E) => Effect<R1, E2, boolean>): <R, A>(self: Effect<R, E, A>) => Effect<R1 | R, E | E2, A>
<R, E, A, R1, E2>(self: Effect<R, E, A>, f: (e: E) => Effect<R1, E2, boolean>): Effect<R | R1, E | E2, A>
} = _schedule.retryWhileEffect_Effect

const try_: {
<A, E>(options: { readonly try: LazyArg<A>; readonly catch: (error: unknown) => E }): Effect<never, E, A>
<A>(evaluate: LazyArg<A>): Effect<never, Cause.UnknownException, A>
Expand Down Expand Up @@ -4132,56 +4073,6 @@ export const repeatOrElse: {
): Effect<R | R2 | R3, E2, B>
} = _schedule.repeatOrElse_Effect

/**
* Repeats this effect until its value satisfies the specified predicate or
* until the first failure.
*
* @since 2.0.0
* @category repetition / recursion
*/
export const repeatUntil: {
<A, B extends A>(f: Refinement<A, B>): <R, E>(self: Effect<R, E, A>) => Effect<R, E, B>
<A>(f: Predicate<A>): <R, E>(self: Effect<R, E, A>) => Effect<R, E, A>
<R, E, A, B extends A>(self: Effect<R, E, A>, f: Predicate<A>): Effect<R, E, B>
<R, E, A>(self: Effect<R, E, A>, f: Predicate<A>): Effect<R, E, A>
} = _schedule.repeatUntil_Effect

/**
* Repeats this effect until its value satisfies the specified effectful
* predicate or until the first failure.
*
* @since 2.0.0
* @category repetition / recursion
*/
export const repeatUntilEffect: {
<A, R2, E2>(f: (a: A) => Effect<R2, E2, boolean>): <R, E>(self: Effect<R, E, A>) => Effect<R2 | R, E2 | E, A>
<R, E, A, R2, E2>(self: Effect<R, E, A>, f: (a: A) => Effect<R2, E2, boolean>): Effect<R | R2, E | E2, A>
} = _schedule.repeatUntilEffect_Effect

/**
* Repeats this effect while its value satisfies the specified effectful
* predicate or until the first failure.
*
* @since 2.0.0
* @category repetition / recursion
*/
export const repeatWhile: {
<A>(f: Predicate<A>): <R, E>(self: Effect<R, E, A>) => Effect<R, E, A>
<R, E, A>(self: Effect<R, E, A>, f: Predicate<A>): Effect<R, E, A>
} = _schedule.repeatWhile_Effect

/**
* Repeats this effect while its value satisfies the specified effectful
* predicate or until the first failure.
*
* @since 2.0.0
* @category repetition / recursion
*/
export const repeatWhileEffect: {
<R1, A, E2>(f: (a: A) => Effect<R1, E2, boolean>): <R, E>(self: Effect<R, E, A>) => Effect<R1 | R, E2 | E, A>
<R, E, R1, A, E2>(self: Effect<R, E, A>, f: (a: A) => Effect<R1, E2, boolean>): Effect<R | R1, E | E2, A>
} = _schedule.repeatWhileEffect_Effect

/**
* Runs this effect according to the specified schedule.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/internal/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ export const mergeAllWith = (
)
})
),
Effect.repeatUntil(Option.isSome),
Effect.repeat({ until: (_): _ is Option.Some<OutDone> => Option.isSome(_) }),
Effect.flatMap((outDone) =>
Ref.update(
lastDone,
Expand Down Expand Up @@ -1325,7 +1325,7 @@ export const mergeAllWith = (
})
})
}),
Effect.repeatWhile(identity),
Effect.repeat({ while: (_) => _ }),
Effect.forkScoped
)
return [queue, input] as const
Expand Down
139 changes: 1 addition & 138 deletions packages/effect/src/internal/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { LazyArg } from "../Function.js"
import { constVoid, dual, pipe } from "../Function.js"
import * as Option from "../Option.js"
import { pipeArguments } from "../Pipeable.js"
import { hasProperty, type Predicate, type Refinement } from "../Predicate.js"
import { hasProperty, type Predicate } from "../Predicate.js"
import * as Random from "../Random.js"
import type * as Ref from "../Ref.js"
import type * as Schedule from "../Schedule.js"
Expand Down Expand Up @@ -1955,66 +1955,6 @@ const repeatOrElseEffectLoop = <R, E, A extends A0, A0, R1, B, R2, E2, C>(
})
}

/** @internal */
export const repeatUntil_Effect = dual<
{
<A, B extends A>(f: Refinement<A, B>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, B>
<A>(f: Predicate<A>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
},
{
<R, E, A, B extends A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, B>
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, A>
}
>(
2,
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) =>
repeatUntilEffect_Effect(self, (a) => core.sync(() => f(a)))
)

/** @internal */
export const repeatUntilEffect_Effect: {
<A, R2, E2>(
f: (a: A) => Effect.Effect<R2, E2, boolean>
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>
<R, E, A, R2, E2>(
self: Effect.Effect<R, E, A>,
f: (a: A) => Effect.Effect<R2, E2, boolean>
): Effect.Effect<R | R2, E | E2, A>
} = dual<
<A, R2, E2>(
f: (a: A) => Effect.Effect<R2, E2, boolean>
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>,
<R, E, A, R2, E2>(
self: Effect.Effect<R, E, A>,
f: (a: A) => Effect.Effect<R2, E2, boolean>
) => Effect.Effect<R | R2, E | E2, A>
>(2, (self, f) =>
core.flatMap(self, (a) =>
core.flatMap(f(a), (result) =>
result ?
core.succeed(a) :
core.flatMap(
core.yieldNow(),
() => repeatUntilEffect_Effect(self, f)
))))

/** @internal */
export const repeatWhile_Effect = dual<
<A>(f: Predicate<A>) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) => Effect.Effect<R, E, A>
>(2, (self, f) => repeatWhileEffect_Effect(self, (a) => core.sync(() => f(a))))

/** @internal */
export const repeatWhileEffect_Effect = dual<
<R1, A, E2>(
f: (a: A) => Effect.Effect<R1, E2, boolean>
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
<R, E, R1, A, E2>(
self: Effect.Effect<R, E, A>,
f: (a: A) => Effect.Effect<R1, E2, boolean>
) => Effect.Effect<R | R1, E | E2, A>
>(2, (self, f) => repeatUntilEffect_Effect(self, (a) => effect.negate(f(a))))

/** @internal */
export const retry_Effect = dual<
<R1, E extends E0, E0, B>(
Expand Down Expand Up @@ -2076,23 +2016,6 @@ export const retry_combined = dual<{
}
)

/** @internal */
export const retryN_Effect = dual<
(n: number) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
<R, E, A>(self: Effect.Effect<R, E, A>, n: number) => Effect.Effect<R, E, A>
>(2, (self, n) => retryN_EffectLoop(self, n))

/** @internal */
const retryN_EffectLoop = <R, E, A>(
self: Effect.Effect<R, E, A>,
n: number
): Effect.Effect<R, E, A> => {
return core.catchAll(self, (e) =>
n <= 0 ?
core.fail(e) :
core.flatMap(core.yieldNow(), () => retryN_EffectLoop(self, n - 1)))
}

/** @internal */
export const retryOrElse_Effect = dual<
<R1, E extends E3, A1, R2, E2, A2, E3>(
Expand Down Expand Up @@ -2131,66 +2054,6 @@ const retryOrElse_EffectLoop = <R, E, A, R1, A1, R2, E2, A2>(
)
}

/** @internal */
export const retryUntil_Effect = dual<
{
<E, E2 extends E>(f: Refinement<E, E2>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E2, A>
<E>(f: Predicate<E>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
},
{
<R, E, A, E2 extends E>(self: Effect.Effect<R, E, A>, f: Refinement<E, E2>): Effect.Effect<R, E2, A>
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>): Effect.Effect<R, E, A>
}
>(2, <R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) =>
retryUntilEffect_Effect(
self,
(e) => core.sync(() => f(e))
))

/** @internal */
export const retryUntilEffect_Effect: {
<R1, E, E2>(
f: (e: E) => Effect.Effect<R1, E2, boolean>
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R1 | R, E | E2, A>
<R, E, A, R1, E2>(
self: Effect.Effect<R, E, A>,
f: (e: E) => Effect.Effect<R1, E2, boolean>
): Effect.Effect<R | R1, E | E2, A>
} = dual<
<R1, E, E2>(
f: (e: E) => Effect.Effect<R1, E2, boolean>
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
<R, E, A, R1, E2>(
self: Effect.Effect<R, E, A>,
f: (e: E) => Effect.Effect<R1, E2, boolean>
) => Effect.Effect<R | R1, E | E2, A>
>(2, (self, f) =>
core.catchAll(self, (e) =>
core.flatMap(f(e), (b) =>
b ?
core.fail(e) :
core.flatMap(
core.yieldNow(),
() => retryUntilEffect_Effect(self, f)
))))

/** @internal */
export const retryWhile_Effect = dual<
<E>(f: Predicate<E>) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) => Effect.Effect<R, E, A>
>(2, (self, f) => retryWhileEffect_Effect(self, (e) => core.sync(() => f(e))))

/** @internal */
export const retryWhileEffect_Effect = dual<
<R1, E, E2>(
f: (e: E) => Effect.Effect<R1, E2, boolean>
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
<R, E, A, R1, E2>(
self: Effect.Effect<R, E, A>,
f: (e: E) => Effect.Effect<R1, E2, boolean>
) => Effect.Effect<R | R1, E | E2, A>
>(2, (self, f) => retryUntilEffect_Effect(self, (e) => effect.negate(f(e))))

/** @internal */
export const schedule_Effect = dual<
<R2, Out>(
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/test/Effect/finalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ describe("Effect", () => {
yield* $(
Ref.get(ref),
Effect.zipLeft(Effect.sleep(Duration.millis(1))),
Effect.repeatUntil((list) => pipe(list, ReadonlyArray.findFirst((s) => s === "start 1"), Option.isSome))
Effect.repeat({ until: (list) => pipe(list, ReadonlyArray.findFirst((s) => s === "start 1"), Option.isSome) })
)
yield* $(Fiber.interrupt(fiber))
yield* $(
Ref.get(ref),
Effect.zipLeft(Effect.sleep(Duration.millis(1))),
Effect.repeatUntil((list) => pipe(list, ReadonlyArray.findFirst((s) => s === "release 2"), Option.isSome))
Effect.repeat({ until: (list) => pipe(list, ReadonlyArray.findFirst((s) => s === "release 2"), Option.isSome) })
)
const result = yield* $(Ref.get(ref))
assert.isTrue(pipe(
Expand Down
Loading

0 comments on commit 0d0dc88

Please sign in to comment.