<const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(
...plans: Plans
): ExecutionPlan<{
provides: make.PlanProvides<Plans>
input: make.PlanInput<Plans>
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never
requirements: Plans[number] extends ExecutionPlan<infer T>
? T["requirements"]
: never
}>Combines multiple execution plans by concatenating their steps in order.
When to use
Use to combine separately defined fallback plans into one ordered plan before applying it to an effect or stream.
Details
The resulting plan tries every step from the first plan, then every step from the next plan, and so on.
export const const merge: <
Plans extends NonEmptyReadonlyArray<
ExecutionPlan<any>
>
>(
...plans: Plans
) => ExecutionPlan<{
provides: make.PlanProvides<Plans>
input: make.PlanInput<Plans>
error: Plans[number] extends ExecutionPlan<
infer T
>
? T["error"]
: never
requirements: Plans[number] extends ExecutionPlan<
infer T
>
? T["requirements"]
: never
}>
Combines multiple execution plans by concatenating their steps in order.
When to use
Use to combine separately defined fallback plans into one ordered plan before
applying it to an effect or stream.
Details
The resulting plan tries every step from the first plan, then every step from
the next plan, and so on.
merge = <const function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans extends type NonEmptyReadonlyArray<A> = readonly [A, ...A[]]A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<any>>>(
...plans: const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>plans: function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans
): interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<{
provides: make.PlanProvides<Plans, unknown>provides: make.type make.PlanProvides<Plans extends ReadonlyArray<any>, Out = unknown> = Plans extends readonly [infer Plan, ...infer Rest] ? make.PlanProvides<Rest, Out & (Plan extends ExecutionPlan<infer T extends {
provides: any;
input: any;
error: any;
requirements: any;
}> ? T["provides"] : unknown)> : Out
Computes the intersection of services provided by a list of execution plans.
PlanProvides<function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans>
input: make.PlanInput<Plans, unknown>input: make.type make.PlanInput<Plans extends ReadonlyArray<any>, Out = unknown> = Plans extends readonly [infer Plan, ...infer Rest] ? make.PlanInput<Rest, Out & (Plan extends ExecutionPlan<infer T extends {
provides: any;
input: any;
error: any;
requirements: any;
}> ? T["input"] : unknown)> : Out
Computes the combined input type consumed by a list of execution plans.
PlanInput<function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans>
error: Plans[number] extends ExecutionPlan<
infer T
>
? T["error"]
: never
error: function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans[number] extends interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<infer function (type parameter) TT> ? function (type parameter) TT["error"] : never
requirements: Plans[number] extends ExecutionPlan<
infer T
>
? T["requirements"]
: never
requirements: function (type parameter) Plans in <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(...plans: Plans): ExecutionPlan<{
provides: make.PlanProvides<Plans>;
input: make.PlanInput<Plans>;
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never;
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never;
}>
Plans[number] extends interface ExecutionPlan<Config extends { provides: any; input: any; error: any; requirements: any; }>A ExecutionPlan can be used with Effect.withExecutionPlan or Stream.withExecutionPlan, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
Example (Defining fallback execution steps)
import { Effect, ExecutionPlan, Schedule } from "effect"
import type { Layer } from "effect"
import type { LanguageModel } from "effect/unstable/ai"
declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
const ThePlan = ExecutionPlan.make(
{
// First try with the bad layer 2 times with a 3 second delay between attempts
provide: layerBad,
attempts: 2,
schedule: Schedule.spaced(3000)
},
// Then try with the bad layer 3 times with a 1 second delay between attempts
{
provide: layerBad,
attempts: 3,
schedule: Schedule.spaced(1000)
},
// Finally try with the good layer.
//
// If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
{
provide: layerGood
}
)
declare const effect: Effect.Effect<
void,
never,
LanguageModel.LanguageModel
>
const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
ExecutionPlan<infer function (type parameter) TT> ? function (type parameter) TT["requirements"] : never
}> => const makeProto: <
Provides,
In,
PlanE,
PlanR
>(
steps: ExecutionPlan<{
provides: Provides
input: In
error: PlanE
requirements: PlanR
}>["steps"]
) => any
makeProto(plans: const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>plans.ReadonlyArray<ExecutionPlan<any>>.flatMap<{
readonly provide: Context.Context<any> | Layer.Layer<any, any, any>;
readonly attempts?: number | undefined;
readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined;
readonly schedule?: Schedule.Schedule<any, any, any, never> | undefined;
}, undefined>(callback: (this: undefined, value: ExecutionPlan<any>, index: number, array: ExecutionPlan<any>[]) => {
readonly provide: Context.Context<any> | Layer.Layer<any, any, any>;
readonly attempts?: number | undefined;
readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined;
readonly schedule?: Schedule.Schedule<any, any, any, never> | undefined;
} | readonly {
readonly provide: Context.Context<any> | Layer.Layer<any, any, any>;
readonly attempts?: number | undefined;
readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined;
readonly schedule?: Schedule.Schedule<any, any, any, never> | undefined;
}[], thisArg?: undefined): {
readonly provide: Context.Context<any> | Layer.Layer<any, any, any>;
readonly attempts?: number | undefined;
readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined;
readonly schedule?: Schedule.Schedule<any, any, any, never> | undefined;
}[]
Calls a defined callback function on each element of an array. Then, flattens the result into
a new array.
This is identical to a map followed by flat with depth 1.
flatMap((plan: ExecutionPlan<any>(parameter) plan: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
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; <…;
}
plan) => plan: ExecutionPlan<any>(parameter) plan: {
steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) =>…;
captureRequirements: Effect.Effect<ExecutionPlan<{ provides: Config["provides"]; input: Config["input"]; error: Config["error"]; requirements: never }>, never, Config["requirements"]>;
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; <…;
}
plan.ExecutionPlan<any>.steps: NonEmptyReadonlyArray<{ readonly provide: Context.Context<Config["provides"]> | Layer.Layer<Config["provides"], Config["error"], Config["requirements"]>; readonly attempts?: number | undefined; readonly while?: ((input: Config["input"]) => Effect.Effect<boolean, Config["error"], Config["requirements"]>) | undefined; readonly schedule?: Schedule.Schedule<any, Config["input"], Config["requirements"]> | undefined }>(property) ExecutionPlan<any>.steps: {
0: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedule.Schedule<any, any,…;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<{ readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedul…;
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<{ readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonl…;
indexOf: (searchElement: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedule.Sc…;
lastIndexOf: (searchElement: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedule.Sc…;
every: { (predicate: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Sched…;
some: (predicate: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedul…;
forEach: (callbackfn: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedu…;
map: (callbackfn: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedu…;
filter: { (predicate: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Sched…;
reduce: { (callbackfn: (previousValue: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedul…;
reduceRight: { (callbackfn: (previousValue: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedul…;
find: { (predicate: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Sched…;
findIndex: (predicate: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedul…;
entries: () => ArrayIterator<[number, { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?…;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<{ readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedul…;
includes: (searchElement: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedule.Sc…;
flatMap: (callback: (this: This, value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedul…;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedule…;
findLast: { (predicate: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Sched…;
findLastIndex: (predicate: (value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedul…;
toReversed: () => Array<{ readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedule.Schedu…;
toSorted: (compareFn?: ((a: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Schedule.…;
toSpliced: { (start: number, deleteCount: number, ...items: Array<{ readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | und…;
with: (index: number, value: { readonly provide: Context.Context<any> | Layer.Layer<any, any, any>; readonly attempts?: number | undefined; readonly while?: ((input: any) => Effect.Effect<boolean, any, any>) | undefined; readonly schedule?: Sche…;
}
steps) as any)