anyType helpers for repeating effects.
export declare namespace Repeat {
/**
* Computes the result type of `Effect.repeat` from the original effect and repeat options.
*
* @category repetition
* @since 2.0.0
*/
export type type Repeat.Return<R, E, A, O extends Repeat.Options<A>> = Effect<O extends {
until: Predicate.Refinement<A, infer B>;
} ? B : O extends {
while: Predicate.Refinement<A, infer B>;
} ? Exclude<A, B> : A, E | (O extends {
schedule: Schedule<infer _Out, infer _I, infer E, infer _R>;
} ? E : never) | (O extends {
while: (...args: Array<any>) => Effect<infer _A, infer E, infer _R>;
} ? E : never) | (O extends {
until: (...args: Array<any>) => Effect<infer _A, infer E, infer _R>;
} ? E : never), R | (O extends {
schedule: Schedule<infer _O, infer _I, infer _E, infer R>;
} ? R : never) | (O extends {
...;
} ? R : never) | (O extends {
...;
} ? R : never)>
Computes the result type of Effect.repeat from the original effect and repeat options.
Return<function (type parameter) R in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>R, function (type parameter) E in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>E, function (type parameter) A in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>A, function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends interface Repeat.Options<A>Options that control whether and how an effect is repeated.
Options<function (type parameter) A in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>A>> = interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends { until: Predicate.Refinement<A, infer B>until: import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) A in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>A, infer function (type parameter) BB> } ? function (type parameter) BB
: function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends { while: Predicate.Refinement<A, infer B>while: import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) A in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>A, infer function (type parameter) BB> } ? type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) A in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>A, function (type parameter) BB>
: function (type parameter) A in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>A,
| function (type parameter) E in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>E
| (function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends { schedule: Schedule<
infer _Out,
infer _I,
infer E,
infer _R
>
(property) schedule: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schedule: interface Schedule<out Output, in Input = unknown, out Error = never, out Env = never>A Schedule defines a strategy for repeating or retrying effects based on some policy.
Example (Defining retry and repeat schedules)
import { Console, Data, Effect, Schedule } from "effect"
class NetworkError extends Data.TaggedError("NetworkError")<{
readonly attempt: number
}> {}
// Basic retry schedule - retry up to 3 times with exponential backoff
const retrySchedule = Schedule.max([
Schedule.exponential("100 millis"),
Schedule.recurs(3)
])
// Basic repeat schedule - repeat every 30 seconds forever
const repeatSchedule: Schedule.Schedule<number, unknown, never> = Schedule
.spaced("30 seconds")
const program = Effect.gen(function*() {
let attempts = 0
const result1 = yield* Effect.retry(
Effect.gen(function*() {
attempts++
if (attempts < 3) {
return yield* Effect.fail(new NetworkError({ attempt: attempts }))
}
return "Success"
}),
retrySchedule
)
console.log(result1) // "Success"
yield* Console.log("heartbeat").pipe(
Effect.repeat(repeatSchedule.pipe(Schedule.upTo({ times: 5 })))
)
})
The Schedule namespace contains types and utilities for working with schedules.
Schedule<infer function (type parameter) _Out_Out, infer function (type parameter) _I_I, infer function (type parameter) EE, infer function (type parameter) _R_R> } ? function (type parameter) EE
: never)
| (function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends { while: (
...args: Array<any>
) => Effect<infer _A, infer E, infer _R>
while: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) EE, infer function (type parameter) _R_R> } ? function (type parameter) EE
: never)
| (function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends { until: (
...args: Array<any>
) => Effect<infer _A, infer E, infer _R>
until: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) EE, infer function (type parameter) _R_R> } ? function (type parameter) EE
: never),
| function (type parameter) R in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>R
| (function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends { schedule: Schedule<
infer _O,
infer _I,
infer _E,
infer R
>
(property) schedule: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schedule: interface Schedule<out Output, in Input = unknown, out Error = never, out Env = never>A Schedule defines a strategy for repeating or retrying effects based on some policy.
Example (Defining retry and repeat schedules)
import { Console, Data, Effect, Schedule } from "effect"
class NetworkError extends Data.TaggedError("NetworkError")<{
readonly attempt: number
}> {}
// Basic retry schedule - retry up to 3 times with exponential backoff
const retrySchedule = Schedule.max([
Schedule.exponential("100 millis"),
Schedule.recurs(3)
])
// Basic repeat schedule - repeat every 30 seconds forever
const repeatSchedule: Schedule.Schedule<number, unknown, never> = Schedule
.spaced("30 seconds")
const program = Effect.gen(function*() {
let attempts = 0
const result1 = yield* Effect.retry(
Effect.gen(function*() {
attempts++
if (attempts < 3) {
return yield* Effect.fail(new NetworkError({ attempt: attempts }))
}
return "Success"
}),
retrySchedule
)
console.log(result1) // "Success"
yield* Console.log("heartbeat").pipe(
Effect.repeat(repeatSchedule.pipe(Schedule.upTo({ times: 5 })))
)
})
The Schedule namespace contains types and utilities for working with schedules.
Schedule<infer function (type parameter) _O_O, infer function (type parameter) _I_I, infer function (type parameter) _E_E, infer function (type parameter) RR> } ? function (type parameter) RR
: never)
| (function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends {
while: (
...args: Array<any>
) => Effect<infer _A, infer _E, infer R>
while: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) RR>
} ? function (type parameter) RR
: never)
| (function (type parameter) O in type Repeat.Return<R, E, A, O extends Repeat.Options<A>>O extends {
until: (
...args: Array<any>
) => Effect<infer _A, infer _E, infer R>
until: (...args: any[]args: interface Array<T>Array<any>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<infer function (type parameter) _A_A, infer function (type parameter) _E_E, infer function (type parameter) RR>
} ? function (type parameter) RR
: never)
> extends infer function (type parameter) ZZ ? function (type parameter) ZZ
: never
/**
* Options that control whether and how an effect is repeated.
*
* @category repetition
* @since 2.0.0
*/
export interface interface Repeat.Options<A>Options that control whether and how an effect is repeated.
Options<function (type parameter) A in Options<A>A> {
Repeat.Options<A>.while?: ((_: A) => boolean | Effect<boolean, any, any>) | undefinedwhile?: ((_: A_: function (type parameter) A in Options<A>A) => boolean | interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean, any, any>) | undefined
Repeat.Options<A>.until?: ((_: A) => boolean | Effect<boolean, any, any>) | undefineduntil?: ((_: A_: function (type parameter) A in Options<A>A) => boolean | interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean, any, any>) | undefined
Repeat.Options<A>.times?: number | undefinedtimes?: number | undefined
Repeat.Options<A>.schedule?: Schedule<any, A, any, any> | undefinedschedule?: interface Schedule<out Output, in Input = unknown, out Error = never, out Env = never>A Schedule defines a strategy for repeating or retrying effects based on some policy.
Example (Defining retry and repeat schedules)
import { Console, Data, Effect, Schedule } from "effect"
class NetworkError extends Data.TaggedError("NetworkError")<{
readonly attempt: number
}> {}
// Basic retry schedule - retry up to 3 times with exponential backoff
const retrySchedule = Schedule.max([
Schedule.exponential("100 millis"),
Schedule.recurs(3)
])
// Basic repeat schedule - repeat every 30 seconds forever
const repeatSchedule: Schedule.Schedule<number, unknown, never> = Schedule
.spaced("30 seconds")
const program = Effect.gen(function*() {
let attempts = 0
const result1 = yield* Effect.retry(
Effect.gen(function*() {
attempts++
if (attempts < 3) {
return yield* Effect.fail(new NetworkError({ attempt: attempts }))
}
return "Success"
}),
retrySchedule
)
console.log(result1) // "Success"
yield* Console.log("heartbeat").pipe(
Effect.repeat(repeatSchedule.pipe(Schedule.upTo({ times: 5 })))
)
})
The Schedule namespace contains types and utilities for working with schedules.
Schedule<any, function (type parameter) A in Options<A>A, any, any> | undefined
}
}