veffect
Version:
powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha
1,627 lines (1,538 loc) • 173 kB
text/typescript
/**
* @since 2.0.0
*/
import type * as Cause from "./Cause.js"
import type * as Chunk from "./Chunk.js"
import type * as Clock from "./Clock.js"
import type { ConfigProvider } from "./ConfigProvider.js"
import type { Console } from "./Console.js"
import type * as Context from "./Context.js"
import type * as Deferred from "./Deferred.js"
import type * as Duration from "./Duration.js"
import type * as Either from "./Either.js"
import type { Equivalence } from "./Equivalence.js"
import type { ExecutionStrategy } from "./ExecutionStrategy.js"
import type * as Exit from "./Exit.js"
import type * as Fiber from "./Fiber.js"
import type * as FiberId from "./FiberId.js"
import type * as FiberRef from "./FiberRef.js"
import type * as FiberRefs from "./FiberRefs.js"
import type * as FiberRefsPatch from "./FiberRefsPatch.js"
import type * as FiberStatus from "./FiberStatus.js"
import type { LazyArg } from "./Function.js"
import { dual } from "./Function.js"
import type * as HashMap from "./HashMap.js"
import type * as HashSet from "./HashSet.js"
import type { TypeLambda } from "./HKT.js"
import * as _console from "./internal/console.js"
import { TagProto } from "./internal/context.js"
import * as effect from "./internal/core-effect.js"
import * as core from "./internal/core.js"
import * as defaultServices from "./internal/defaultServices.js"
import * as circular from "./internal/effect/circular.js"
import * as fiberRuntime from "./internal/fiberRuntime.js"
import * as layer from "./internal/layer.js"
import * as query from "./internal/query.js"
import * as _runtime from "./internal/runtime.js"
import * as _schedule from "./internal/schedule.js"
import type * as Layer from "./Layer.js"
import type { LogLevel } from "./LogLevel.js"
import type * as Metric from "./Metric.js"
import type * as MetricLabel from "./MetricLabel.js"
import type * as Option from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
import type { Predicate, Refinement } from "./Predicate.js"
import type * as Random from "./Random.js"
import type * as Ref from "./Ref.js"
import * as Request from "./Request.js"
import type { RequestBlock } from "./RequestBlock.js"
import type { RequestResolver } from "./RequestResolver.js"
import type * as Runtime from "./Runtime.js"
import type * as RuntimeFlags from "./RuntimeFlags.js"
import type * as RuntimeFlagsPatch from "./RuntimeFlagsPatch.js"
import type * as Schedule from "./Schedule.js"
import * as Scheduler from "./Scheduler.js"
import type * as Scope from "./Scope.js"
import type * as Supervisor from "./Supervisor.js"
import type * as Tracer from "./Tracer.js"
import type { Concurrency, Covariant, MergeRecord, NoInfer, NotFunction } from "./Types.js"
import type * as Unify from "./Unify.js"
// -------------------------------------------------------------------------------------
// models
// -------------------------------------------------------------------------------------
/**
* @since 2.0.0
* @category symbols
*/
export const EffectTypeId: unique symbol = core.EffectTypeId
/**
* @since 2.0.0
* @category symbols
*/
export type EffectTypeId = typeof EffectTypeId
/**
* 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`.
*
* `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.
*
* @since 2.0.0
* @category models
*/
export interface Effect<out A, out E = never, out R = never> extends Effect.Variance<A, E, R>, Pipeable {
readonly [Unify.typeSymbol]?: unknown
readonly [Unify.unifySymbol]?: EffectUnify<this>
readonly [Unify.ignoreSymbol]?: EffectUnifyIgnore
}
/**
* @since 2.0.0
* @category models
*/
export interface EffectUnify<A extends { [Unify.typeSymbol]?: any }>
extends Either.EitherUnify<A>, Option.OptionUnify<A>, Context.TagUnify<A>
{
Effect?: () => A[Unify.typeSymbol] extends Effect<infer A0, infer E0, infer R0> | infer _ ? Effect<A0, E0, R0> : never
}
/**
* @category models
* @since 2.0.0
*/
export interface EffectUnifyIgnore {
Tag?: true
Option?: true
Either?: true
}
/**
* @category type lambdas
* @since 2.0.0
*/
export interface EffectTypeLambda extends TypeLambda {
readonly type: Effect<this["Target"], this["Out1"], this["Out2"]>
}
/**
* @since 2.0.0
* @category models
*/
export interface Blocked<out A, out E> extends Effect<A, E> {
readonly _op: "Blocked"
readonly effect_instruction_i0: RequestBlock
readonly effect_instruction_i1: Effect<A, E>
}
/**
* @since 2.0.0
* @category models
*/
declare module "./Context.js" {
interface Tag<Id, Value> extends Effect<Value, never, Id> {}
interface TagUnifyIgnore {
Effect?: true
Either?: true
Option?: true
}
}
/**
* @since 2.0.0
* @category models
*/
declare module "./Either.js" {
interface Left<L, R> extends Effect<R, L> {
readonly _tag: "Left"
}
interface Right<L, R> extends Effect<R, L> {
readonly _tag: "Right"
}
interface EitherUnifyIgnore {
Effect?: true
Tag?: true
Option?: true
}
}
/**
* @since 2.0.0
* @category models
*/
declare module "./Option.js" {
interface None<A> extends Effect<A, Cause.NoSuchElementException> {
readonly _tag: "None"
}
interface Some<A> extends Effect<A, Cause.NoSuchElementException> {
readonly _tag: "Some"
}
interface OptionUnifyIgnore {
Effect?: true
Tag?: true
Either?: true
}
}
/**
* @since 2.0.0
*/
export declare namespace Effect {
/**
* @since 2.0.0
* @category models
*/
export interface Variance<out A, out E, out R> {
readonly [EffectTypeId]: VarianceStruct<A, E, R>
}
/**
* @since 2.0.0
* @category models
*/
export interface VarianceStruct<out A, out E, out R> {
readonly _V: string
readonly _A: Covariant<A>
readonly _E: Covariant<E>
readonly _R: Covariant<R>
}
/**
* @since 2.0.0
* @category type-level
*/
export type Context<T extends Effect<any, any, any>> = [T] extends [Effect<infer _A, infer _E, infer _R>] ? _R : never
/**
* @since 2.0.0
* @category type-level
*/
export type Error<T extends Effect<any, any, any>> = [T] extends [Effect<infer _A, infer _E, infer _R>] ? _E : never
/**
* @since 2.0.0
* @category type-level
*/
export type Success<T extends Effect<any, any, any>> = [T] extends [Effect<infer _A, infer _E, infer _R>] ? _A : never
}
// -------------------------------------------------------------------------------------
// refinements
// -------------------------------------------------------------------------------------
/**
* This function returns `true` if the specified value is an `Effect` value,
* `false` otherwise.
*
* This function can be useful for checking the type of a value before
* attempting to operate on it as an `Effect` value. For example, you could
* use `isEffect` to check the type of a value before using it as an
* argument to a function that expects an `Effect` value.
*
* @param u - The value to check for being an `Effect` value.
*
* @returns `true` if the specified value is an `Effect` value, `false`
* otherwise.
*
* @since 2.0.0
* @category refinements
*/
export const isEffect: (u: unknown) => u is Effect<unknown, unknown, unknown> = core.isEffect
// -------------------------------------------------------------------------------------
// caching
// -------------------------------------------------------------------------------------
/**
* Returns an effect that, if evaluated, will return the cached result of this
* effect. Cached results will expire after `timeToLive` duration.
*
* @since 2.0.0
* @category caching
*/
export const cachedWithTTL: {
(timeToLive: Duration.DurationInput): <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A, E>, never, R>
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.DurationInput): Effect<Effect<A, E>, never, R>
} = circular.cached
/**
* Returns an effect that, if evaluated, will return the cached result of this
* effect. Cached results will expire after `timeToLive` duration. In
* addition, returns an effect that can be used to invalidate the current
* cached value before the `timeToLive` duration expires.
*
* @since 2.0.0
* @category caching
*/
export const cachedInvalidateWithTTL: {
(timeToLive: Duration.DurationInput): <A, E, R>(
self: Effect<A, E, R>
) => Effect<[Effect<A, E>, Effect<void>], never, R>
<A, E, R>(
self: Effect<A, E, R>,
timeToLive: Duration.DurationInput
): Effect<[Effect<A, E>, Effect<void>], never, R>
} = circular.cachedInvalidateWithTTL
/**
* Returns an effect that, if evaluated, will return the lazily computed
* result of this effect.
*
* @since 2.0.0
* @category caching
*/
export const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>> = effect.memoize
/**
* Returns a memoized version of the specified effectual function.
*
* @since 2.0.0
* @category caching
*/
export const cachedFunction: <A, B, E, R>(
f: (a: A) => Effect<B, E, R>,
eq?: Equivalence<A>
) => Effect<(a: A) => Effect<B, E, R>> = circular.cachedFunction
/**
* Returns an effect that will be executed at most once, even if it is
* evaluated multiple times.
*
* @example
* import * as Effect from "effect/Effect"
* import * as Console from "effect/Console"
*
* const program = Effect.gen(function* (_) {
* const twice = Console.log("twice")
* yield* _(twice, Effect.repeatN(1))
* const once = yield* _(Console.log("once"), Effect.once)
* yield* _(once, Effect.repeatN(1))
* })
*
* Effect.runFork(program)
* // Output:
* // twice
* // twice
* // once
*
* @since 2.0.0
* @category caching
*/
export const once: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<void, E, R>> = effect.once
// -------------------------------------------------------------------------------------
// collecting & elements
// -------------------------------------------------------------------------------------
/**
* Runs all the provided effects in sequence respecting the structure provided in input.
*
* Supports multiple arguments, a single argument tuple / array or record / struct.
*
* @since 2.0.0
* @category collecting & elements
*/
export const all: <
const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>,
O extends {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: boolean | undefined
readonly mode?: "default" | "validate" | "either" | undefined
}
>(arg: Arg, options?: O) => All.Return<Arg, O> = fiberRuntime.all
/**
* Data-last variant of `Effect.all`.
*
* Runs all the provided effects in sequence respecting the structure provided in input.
*
* Supports multiple arguments, a single argument tuple / array or record / struct.
*
* @since 2.0.0
* @category collecting & elements
*/
export const allWith: <
O extends {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: boolean | undefined
readonly mode?: "default" | "validate" | "either" | undefined
}
>(
options?: O
) => <const Arg extends Iterable<Effect<any, any, any>> | Record<string, Effect<any, any, any>>>(
arg: Arg
) => All.Return<Arg, O> = fiberRuntime.allWith
/**
* @since 2.0.0
*/
export declare namespace All {
/**
* @since 2.0.0
*/
export type EffectAny = Effect<any, any, any>
/**
* @since 2.0.0
*/
export type ReturnIterable<T extends Iterable<EffectAny>, Discard extends boolean, Mode> = [T] extends
[Iterable<Effect.Variance<infer R0, infer L0, infer R>>] ? Effect<
Discard extends true ? void : Mode extends "either" ? Array<Either.Either<R0, L0>> : Array<R0>,
Mode extends "either" ? never
: Mode extends "validate" ? Array<Option.Option<L0>>
: L0,
R
>
: never
/**
* @since 2.0.0
*/
export type ReturnTuple<T extends ReadonlyArray<unknown>, Discard extends boolean, Mode> = Effect<
Discard extends true ? void
: T[number] extends never ? []
: Mode extends "either" ? {
-readonly [K in keyof T]: [T[K]] extends [Effect.Variance<infer _A, infer _E, infer _R>] ?
Either.Either<_A, _E>
: never
}
: { -readonly [K in keyof T]: [T[K]] extends [Effect.Variance<infer _A, infer _E, infer _R>] ? _A : never },
Mode extends "either" ? never
: T[number] extends never ? never
: Mode extends "validate" ? {
-readonly [K in keyof T]: [T[K]] extends [Effect.Variance<infer _A, infer _E, infer _R>] ? Option.Option<_E>
: never
}
: [T[number]] extends [{ [EffectTypeId]: { _E: (_: never) => infer E } }] ? E
: never,
T[number] extends never ? never
: [T[number]] extends [{ [EffectTypeId]: { _R: (_: never) => infer R } }] ? R
: never
> extends infer X ? X : never
/**
* @since 2.0.0
*/
export type ReturnObject<T, Discard extends boolean, Mode> = [T] extends [{ [K: string]: EffectAny }] ? Effect<
Discard extends true ? void
: Mode extends "either" ? {
-readonly [K in keyof T]: [T[K]] extends [Effect.Variance<infer _A, infer _E, infer _R>] ?
Either.Either<_A, _E>
: never
}
: { -readonly [K in keyof T]: [T[K]] extends [Effect.Variance<infer _A, infer _E, infer _R>] ? _A : never },
Mode extends "either" ? never
: keyof T extends never ? never
: Mode extends "validate" ? {
-readonly [K in keyof T]: [T[K]] extends [Effect.Variance<infer _A, infer _E, infer _R>] ? Option.Option<_E>
: never
}
: [T[keyof T]] extends [{ [EffectTypeId]: { _E: (_: never) => infer E } }] ? E
: never,
keyof T extends never ? never
: [T[keyof T]] extends [{ [EffectTypeId]: { _R: (_: never) => infer R } }] ? R
: never
>
: never
/**
* @since 2.0.0
*/
export type IsDiscard<A> = [Extract<A, { readonly discard: true }>] extends [never] ? false : true
/**
* @since 2.0.0
*/
export type ExtractMode<A> = [A] extends [{ mode: infer M }] ? M : "default"
/**
* @since 2.0.0
*/
export type Return<
Arg extends Iterable<EffectAny> | Record<string, EffectAny>,
O extends {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: boolean | undefined
readonly mode?: "default" | "validate" | "either" | undefined
}
> = [Arg] extends [ReadonlyArray<EffectAny>] ? ReturnTuple<Arg, IsDiscard<O>, ExtractMode<O>>
: [Arg] extends [Iterable<EffectAny>] ? ReturnIterable<Arg, IsDiscard<O>, ExtractMode<O>>
: [Arg] extends [Record<string, EffectAny>] ? ReturnObject<Arg, IsDiscard<O>, ExtractMode<O>>
: never
}
/**
* Evaluate and run each effect in the structure and collect the results,
* discarding results from failed effects.
*
* @since 2.0.0
* @category collecting & elements
*/
export const allSuccesses: <X extends Effect<any, any, any>>(
elements: Iterable<X>,
options?:
| {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
}
| undefined
) => Effect<Array<Effect.Success<X>>, never, Effect.Context<X>> = fiberRuntime.allSuccesses
/**
* Drops all elements until the effectful predicate returns true.
*
* @since 2.0.0
* @category collecting & elements
*/
export const dropUntil: {
<A, E, R>(
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): (elements: Iterable<A>) => Effect<Array<A>, E, R>
<A, E, R>(elements: Iterable<A>, predicate: (a: A, i: number) => Effect<boolean, E, R>): Effect<Array<A>, E, R>
} = effect.dropUntil
/**
* Drops all elements so long as the predicate returns true.
*
* @since 2.0.0
* @category collecting & elements
*/
export const dropWhile: {
<A, E, R>(
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): (elements: Iterable<A>) => Effect<Array<A>, E, R>
<A, E, R>(elements: Iterable<A>, predicate: (a: A, i: number) => Effect<boolean, E, R>): Effect<Array<A>, E, R>
} = effect.dropWhile
/**
* Determines whether all elements of the `Collection<A>` satisfies the effectual
* predicate `f`.
*
* @since 2.0.0
* @category collecting & elements
*/
export const every: {
<A, E, R>(f: (a: A, i: number) => Effect<boolean, E, R>): (elements: Iterable<A>) => Effect<boolean, E, R>
<A, E, R>(elements: Iterable<A>, f: (a: A, i: number) => Effect<boolean, E, R>): Effect<boolean, E, R>
} = effect.every
/**
* Determines whether any element of the `Iterable<A>` satisfies the effectual
* predicate `f`.
*
* @since 2.0.0
* @category collecting & elements
*/
export const exists: {
<A, E, R>(
f: (a: A, i: number) => Effect<boolean, E, R>,
options?:
| {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
}
| undefined
): (elements: Iterable<A>) => Effect<boolean, E, R>
<A, E, R>(
elements: Iterable<A>,
f: (a: A, i: number) => Effect<boolean, E, R>,
options?:
| {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
}
| undefined
): Effect<boolean, E, R>
} = fiberRuntime.exists
/**
* Filters the collection using the specified effectful predicate.
*
* @since 2.0.0
* @category collecting & elements
*/
export const filter: {
<A, E, R>(
f: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly negate?: boolean | undefined
} | undefined
): (elements: Iterable<A>) => Effect<Array<A>, E, R>
<A, E, R>(
elements: Iterable<A>,
f: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly negate?: boolean | undefined
} | undefined
): Effect<Array<A>, E, R>
} = fiberRuntime.filter
/**
* Performs a filter and map in a single step.
*
* @since 2.0.0
* @category collecting & elements
*/
export const filterMap: {
<Eff extends Effect<any, any, any>, B>(
pf: (a: Effect.Success<Eff>) => Option.Option<B>
): (elements: Iterable<Eff>) => Effect<Array<B>, Effect.Error<Eff>, Effect.Context<Eff>>
<Eff extends Effect<any, any, any>, B>(
elements: Iterable<Eff>,
pf: (a: Effect.Success<Eff>) => Option.Option<B>
): Effect<Array<B>, Effect.Error<Eff>, Effect.Context<Eff>>
} = effect.filterMap
/**
* Returns the first element that satisfies the effectful predicate.
*
* @since 2.0.0
* @category collecting & elements
*/
export const findFirst: {
<A, E, R>(
f: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): (elements: Iterable<A>) => Effect<Option.Option<A>, E, R>
<A, E, R>(
elements: Iterable<A>,
f: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): Effect<Option.Option<A>, E, R>
} = effect.findFirst
/**
* This function takes an iterable of `Effect` values and returns a new
* `Effect` value that represents the first `Effect` value in the iterable
* that succeeds. If all of the `Effect` values in the iterable fail, then
* the resulting `Effect` value will fail as well.
*
* This function is sequential, meaning that the `Effect` values in the
* iterable will be executed in sequence, and the first one that succeeds
* will determine the outcome of the resulting `Effect` value.
*
* @param effects - The iterable of `Effect` values to evaluate.
*
* @returns A new `Effect` value that represents the first successful
* `Effect` value in the iterable, or a failed `Effect` value if all of the
* `Effect` values in the iterable fail.
*
* @since 2.0.0
* @category collecting & elements
*/
export const firstSuccessOf: <Eff extends Effect<any, any, any>>(
effects: Iterable<Eff>
) => Effect<Effect.Success<Eff>, Effect.Error<Eff>, Effect.Context<Eff>> = effect.firstSuccessOf
/**
* @since 2.0.0
* @category collecting & elements
*/
export const forEach: {
<A, B, E, R>(
f: (a: A, i: number) => Effect<B, E, R>,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: false | undefined
} | undefined
): (self: Iterable<A>) => Effect<Array<B>, E, R>
<A, B, E, R>(
f: (a: A, i: number) => Effect<B, E, R>,
options: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard: true
}
): (self: Iterable<A>) => Effect<void, E, R>
<A, B, E, R>(
self: Iterable<A>,
f: (a: A, i: number) => Effect<B, E, R>,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: false | undefined
} | undefined
): Effect<Array<B>, E, R>
<A, B, E, R>(
self: Iterable<A>,
f: (a: A, i: number) => Effect<B, E, R>,
options: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard: true
}
): Effect<void, E, R>
} = fiberRuntime.forEach
/**
* Returns a successful effect with the head of the collection if the collection
* is non-empty, or fails with the error `None` if the collection is empty.
*
* @since 2.0.0
* @category collecting & elements
*/
export const head: <A, E, R>(self: Effect<Iterable<A>, E, R>) => Effect<A, Cause.NoSuchElementException | E, R> =
effect.head
/**
* Merges an `Iterable<Effect<A, E, R>>` to a single effect, working
* sequentially.
*
* @since 2.0.0
* @category collecting & elements
*/
export const mergeAll: {
<Z, Eff extends Effect<any, any, any>>(
zero: Z,
f: (z: Z, a: Effect.Success<Eff>, i: number) => Z,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): (elements: Iterable<Eff>) => Effect<Z, Effect.Error<Eff>, Effect.Context<Eff>>
<Eff extends Effect<any, any, any>, Z>(
elements: Iterable<Eff>,
zero: Z,
f: (z: Z, a: Effect.Success<Eff>, i: number) => Z,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): Effect<Z, Effect.Error<Eff>, Effect.Context<Eff>>
} = fiberRuntime.mergeAll
/**
* Feeds elements of type `A` to a function `f` that returns an effect.
* Collects all successes and failures in a tupled fashion.
*
* @since 2.0.0
* @category collecting & elements
*/
export const partition: {
<A, B, E, R>(
f: (a: A, i: number) => Effect<B, E, R>,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): (elements: Iterable<A>) => Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>
<A, B, E, R>(
elements: Iterable<A>,
f: (a: A, i: number) => Effect<B, E, R>,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>
} = fiberRuntime.partition
/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially
* from left to right.
*
* @since 2.0.0
* @category collecting & elements
*/
export const reduce: {
<Z, A, E, R>(zero: Z, f: (z: Z, a: A, i: number) => Effect<Z, E, R>): (elements: Iterable<A>) => Effect<Z, E, R>
<A, Z, E, R>(elements: Iterable<A>, zero: Z, f: (z: Z, a: A, i: number) => Effect<Z, E, R>): Effect<Z, E, R>
} = effect.reduce
/**
* Reduces an `Iterable<Effect<A, E, R>>` to a single effect.
*
* @since 2.0.0
* @category collecting & elements
*/
export const reduceEffect: {
<Z, E, R, Eff extends Effect<any, any, any>>(
zero: Effect<Z, E, R>,
f: (acc: NoInfer<Z>, a: Effect.Success<Eff>, i: number) => Z,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): (elements: Iterable<Eff>) => Effect<Z, E | Effect.Error<Eff>, R | Effect.Context<Eff>>
<Eff extends Effect<any, any, any>, Z, E, R>(
elements: Iterable<Eff>,
zero: Effect<Z, E, R>,
f: (acc: NoInfer<Z>, a: Effect.Success<Eff>, i: number) => Z,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): Effect<Z, E | Effect.Error<Eff>, R | Effect.Context<Eff>>
} = fiberRuntime.reduceEffect
/**
* Folds an `Iterable<A>` using an effectual function f, working sequentially from left to right.
*
* @since 2.0.0
* @category collecting & elements
*/
export const reduceRight: {
<A, Z, R, E>(zero: Z, f: (a: A, z: Z, i: number) => Effect<Z, E, R>): (elements: Iterable<A>) => Effect<Z, E, R>
<A, Z, R, E>(elements: Iterable<A>, zero: Z, f: (a: A, z: Z, i: number) => Effect<Z, E, R>): Effect<Z, E, R>
} = effect.reduceRight
/**
* Folds over the elements in this chunk from the left, stopping the fold early
* when the predicate is not satisfied.
*
* @since 2.0.0
* @category collecting & elements
*/
export const reduceWhile: {
<Z, A, E, R>(
zero: Z,
options: { readonly while: Predicate<Z>; readonly body: (s: Z, a: A, i: number) => Effect<Z, E, R> }
): (elements: Iterable<A>) => Effect<Z, E, R>
<A, Z, E, R>(
elements: Iterable<A>,
zero: Z,
options: { readonly while: Predicate<Z>; readonly body: (s: Z, a: A, i: number) => Effect<Z, E, R> }
): Effect<Z, E, R>
} = effect.reduceWhile
/**
* Replicates the given effect `n` times.
*
* @since 2.0.0
* @category collecting & elements
*/
export const replicate: {
(n: number): <A, E, R>(self: Effect<A, E, R>) => Array<Effect<A, E, R>>
<A, E, R>(self: Effect<A, E, R>, n: number): Array<Effect<A, E, R>>
} = fiberRuntime.replicate
/**
* Performs this effect the specified number of times and collects the
* results.
*
* @since 2.0.0
* @category collecting & elements
*/
export const replicateEffect: {
(
n: number,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: false | undefined
}
): <A, E, R>(self: Effect<A, E, R>) => Effect<Array<A>, E, R>
(
n: number,
options: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard: true
}
): <A, E, R>(self: Effect<A, E, R>) => Effect<void, E, R>
<A, E, R>(
self: Effect<A, E, R>,
n: number,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: false | undefined
}
): Effect<Array<A>, E, R>
<A, E, R>(
self: Effect<A, E, R>,
n: number,
options: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard: true
}
): Effect<void, E, R>
} = fiberRuntime.replicateEffect
/**
* Takes elements until the effectual predicate returns true.
*
* @since 2.0.0
* @category collecting & elements
*/
export const takeUntil: {
<A, R, E>(
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): (elements: Iterable<A>) => Effect<Array<A>, E, R>
<A, E, R>(
elements: Iterable<A>,
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): Effect<Array<A>, E, R>
} = effect.takeUntil
/**
* Takes all elements so long as the effectual predicate returns true.
*
* @since 2.0.0
* @category collecting & elements
*/
export const takeWhile: {
<A, E, R>(
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): (elements: Iterable<A>) => Effect<Array<A>, E, R>
<A, E, R>(
elements: Iterable<A>,
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
): Effect<Array<A>, E, R>
} = effect.takeWhile
/**
* Feeds elements of type `A` to `f` and accumulates all errors in error
* channel or successes in success channel.
*
* This combinator is lossy meaning that if there are errors all successes
* will be lost. To retain all information please use `partition`.
*
* @since 2.0.0
* @category collecting & elements
*/
export const validateAll: {
<A, B, E, R>(
f: (a: A, i: number) => Effect<B, E, R>,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: false | undefined
} | undefined
): (elements: Iterable<A>) => Effect<Array<B>, Array<E>, R>
<A, B, E, R>(
f: (a: A, i: number) => Effect<B, E, R>,
options: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard: true
}
): (elements: Iterable<A>) => Effect<void, Array<E>, R>
<A, B, E, R>(
elements: Iterable<A>,
f: (a: A, i: number) => Effect<B, E, R>,
options?: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard?: false | undefined
} | undefined
): Effect<Array<B>, Array<E>, R>
<A, B, E, R>(
elements: Iterable<A>,
f: (a: A, i: number) => Effect<B, E, R>,
options: {
readonly concurrency?: Concurrency | undefined
readonly batching?: boolean | "inherit" | undefined
readonly discard: true
}
): Effect<void, Array<E>, R>
} = fiberRuntime.validateAll
/**
* Feeds elements of type `A` to `f` until it succeeds. Returns first success
* or the accumulation of all errors.
*
* If `elements` is empty then `Effect.fail([])` is returned.
*
* @example
* import * as Effect from "effect/Effect"
* import * as Exit from "effect/Exit"
*
* const f = (n: number) => (n > 0 ? Effect.succeed(n) : Effect.fail(`${n} is negative`))
*
* assert.deepStrictEqual(Effect.runSyncExit(Effect.validateFirst([], f)), Exit.fail([]))
* assert.deepStrictEqual(Effect.runSyncExit(Effect.validateFirst([1, 2], f)), Exit.succeed(1))
* assert.deepStrictEqual(Effect.runSyncExit(Effect.validateFirst([1, -1], f)), Exit.succeed(1))
* assert.deepStrictEqual(Effect.runSyncExit(Effect.validateFirst([-1, 2], f)), Exit.succeed(2))
* assert.deepStrictEqual(Effect.runSyncExit(Effect.validateFirst([-1, -2], f)), Exit.fail(['-1 is negative', '-2 is negative']))
*
* @since 2.0.0
* @category collecting & elements
*/
export const validateFirst: {
<A, B, E, R>(
f: (a: A, i: number) => Effect<B, E, R>,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): (elements: Iterable<A>) => Effect<B, Array<E>, R>
<A, B, E, R>(
elements: Iterable<A>,
f: (a: A, i: number) => Effect<B, E, R>,
options?:
| { readonly concurrency?: Concurrency | undefined; readonly batching?: boolean | "inherit" | undefined }
| undefined
): Effect<B, Array<E>, R>
} = fiberRuntime.validateFirst
// -------------------------------------------------------------------------------------
// constructors
// -------------------------------------------------------------------------------------
/**
* Imports an asynchronous side-effect into a pure `Effect` value. The callback
* function `Effect<A, E, R> => void` **MUST** be called at most once.
*
* The registration function can optionally return an Effect, which will be
* executed if the `Fiber` executing this Effect is interrupted.
*
* The registration function can also receive an `AbortSignal` if required for
* interruption.
*
* The `FiberId` of the fiber that may complete the async callback may also be
* specified. This is called the "blocking fiber" because it suspends the fiber
* executing the `async` Effect (i.e. semantically blocks the fiber from making
* progress). Specifying this fiber id in cases where it is known will improve
* diagnostics, but not affect the behavior of the returned effect.
*
* @since 2.0.0
* @category constructors
*/
export const async: <A, E = never, R = never>(
register: (callback: (_: Effect<A, E, R>) => void, signal: AbortSignal) => void | Effect<void, never, R>,
blockingOn?: FiberId.FiberId
) => Effect<A, E, R> = core.async
/**
* Converts an asynchronous, callback-style API into an `Effect`, which will
* be executed asynchronously.
*
* With this variant, the registration function may return a an `Effect`.
*
* @since 2.0.0
* @category constructors
*/
export const asyncEffect: <A, E, R, R3, E2, R2>(
register: (callback: (_: Effect<A, E, R>) => void) => Effect<Effect<void, never, R3> | void, E2, R2>
) => Effect<A, E | E2, R | R2 | R3> = _runtime.asyncEffect
/**
* Low level constructor that enables for custom stack tracing cutpoints.
*
* It is meant to be called with a bag of instructions that become available in the "this" of the effect.
*
* @example
* import * as Effect from "effect/Effect"
*
* const throwingFunction = () => { throw new Error() }
* const blowUp = Effect.custom(throwingFunction, function() {
* return Effect.succeed(this.effect_instruction_i0())
* })
*
* @since 2.0.0
* @category constructors
*/
export const custom: {
<X, A, E, R>(i0: X, body: (this: { effect_instruction_i0: X }) => Effect<A, E, R>): Effect<A, E, R>
<X, Y, A, E, R>(
i0: X,
i1: Y,
body: (this: { effect_instruction_i0: X; effect_instruction_i1: Y }) => Effect<A, E, R>
): Effect<A, E, R>
<X, Y, Z, A, E, R>(
i0: X,
i1: Y,
i2: Z,
body: (this: { effect_instruction_i0: X; effect_instruction_i1: Y; effect_instruction_i2: Z }) => Effect<A, E, R>
): Effect<A, E, R>
} = core.custom
/**
* @since 2.0.0
* @category constructors
*/
export const withFiberRuntime: <A, E = never, R = never>(
withRuntime: (
fiber: Fiber.RuntimeFiber<A, E>,
status: FiberStatus.Running
) => Effect<A, E, R>
) => Effect<A, E, R> = core.withFiberRuntime
/**
* @since 2.0.0
* @category constructors
*/
export const fail: <E>(error: E) => Effect<never, E> = core.fail
/**
* @since 2.0.0
* @category constructors
*/
export const failSync: <E>(evaluate: LazyArg<E>) => Effect<never, E> = core.failSync
/**
* @since 2.0.0
* @category constructors
*/
export const failCause: <E>(cause: Cause.Cause<E>) => Effect<never, E> = core.failCause
/**
* @since 2.0.0
* @category constructors
*/
export const failCauseSync: <E>(evaluate: LazyArg<Cause.Cause<E>>) => Effect<never, E> = core.failCauseSync
/**
* @since 2.0.0
* @category constructors
*/
export const die: (defect: unknown) => Effect<never> = core.die
/**
* Returns an effect that dies with a `RuntimeException` having the specified
* text message. This method can be used for terminating a fiber because a
* defect has been detected in the code.
*
* @since 2.0.0
* @category constructors
*/
export const dieMessage: (message: string) => Effect<never> = core.dieMessage
/**
* @since 2.0.0
* @category constructors
*/
export const dieSync: (evaluate: LazyArg<unknown>) => Effect<never> = core.dieSync
/**
* @since 2.0.0
* @category constructors
*/
export const gen: {
<Eff extends EffectGen<any, any, any>, AEff>(
f: (resume: Adapter) => Generator<Eff, AEff, any>
): Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [EffectGen<any, infer E, any>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [EffectGen<any, any, infer R>] ? R : never
>
<Self, Eff extends EffectGen<any, any, any>, AEff>(
self: Self,
f: (this: Self, resume: Adapter) => Generator<Eff, AEff, any>
): Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [EffectGen<any, infer E, any>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [EffectGen<any, any, infer R>] ? R : never
>
} = effect.gen
/**
* @category models
* @since 2.0.0
*/
export interface EffectGen<out A, out E, out R> {
readonly _A: () => A
readonly _E: () => E
readonly _R: () => R
readonly value: Effect<A, E, R>
[Symbol.iterator](): Generator<EffectGen<A, E, R>, A>
}
/**
* @since 2.0.0
* @category models
*/
export interface Adapter {
<A, E, R>(self: Effect<A, E, R>): EffectGen<A, E, R>
<A, _A, _E, _R>(a: A, ab: (a: A) => Effect<_A, _E, _R>): EffectGen<_A, _E, _R>
<A, B, _A, _E, _R>(a: A, ab: (a: A) => B, bc: (b: B) => Effect<_A, _E, _R>): EffectGen<_A, _E, _R>
<A, B, C, _A, _E, _R>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => Effect<_A, _E, _R>): EffectGen<_A, _E, _R>
<A, B, C, D, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (g: H) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, N, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => N,
no: (n: N) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => N,
no: (n: N) => O,
op: (o: O) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => N,
no: (n: N) => O,
op: (o: O) => P,
pq: (p: P) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => N,
no: (n: N) => O,
op: (o: O) => P,
pq: (p: P) => Q,
qr: (q: Q) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => N,
no: (n: N) => O,
op: (o: O) => P,
pq: (p: P) => Q,
qr: (q: Q) => R,
rs: (r: R) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => N,
no: (n: N) => O,
op: (o: O) => P,
pq: (p: P) => Q,
qr: (q: Q) => R,
rs: (r: R) => S,
st: (s: S) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, _A, _E, _R>(
a: A,
ab: (a: A) => B,
bc: (b: B) => C,
cd: (c: C) => D,
de: (d: D) => E,
ef: (e: E) => F,
fg: (f: F) => G,
gh: (g: G) => H,
hi: (h: H) => I,
ij: (i: I) => J,
jk: (j: J) => K,
kl: (k: K) => L,
lm: (l: L) => M,
mn: (m: M) => N,
no: (n: N) => O,
op: (o: O) => P,
pq: (p: P) => Q,
qr: (q: Q) => R,
rs: (r: R) => S,
st: (s: S) => T,
tu: (s: T) => Effect<_A, _E, _R>
): EffectGen<_A, _E, _R>
}
/**
* Returns a effect that will never produce anything. The moral equivalent of
* `while(true) {}`, only without the wasted CPU cycles.
*
* @since 2.0.0
* @category constructors
*/
export const never: Effect<never> = core.never
/**
* Requires the option produced by this value to be `None`.
*
* @since 2.0.0
* @category constructors
*/
export const none: <A, E, R>(
self: Effect<Option.Option<A>, E, R>
) => Effect<void, E | Cause.NoSuchElementException, R> = effect.none
/**
* Like `tryPromise` but produces a defect in case of errors.
*
* An optional `AbortSignal` can be provided to allow for interruption of the
* wrapped Promise api.
*
* @since 2.0.0
* @category constructors
*/
export const promise: <A>(
evaluate: (signal: AbortSignal) => PromiseLike<A>
) => Effect<A> = effect.promise
/**
* @since 2.0.0
* @category constructors
*/
export const succeed: <A>(value: A) => Effect<A> = core.succeed
/**
* Returns an effect which succeeds with `None`.
*
* @since 2.0.0
* @category constructors
*/
export const succeedNone: Effect<Option.Option<never>> = effect.succeedNone
/**
* Returns an effect which succeeds with the value wrapped in a `Some`.
*
* @since 2.0.0
* @category constructors
*/
export const succeedSome: <A>(value: A) => Effect<Option.Option<A>> = effect.succeedSome
/**
* @since 2.0.0
* @category constructors
*/
export const suspend: <A, E, R>(effect: LazyArg<Effect<A, E, R>>) => Effect<A, E, R> = core.suspend
/**
* @since 2.0.0
* @category constructors
*/
export const sync: <A>(evaluate: LazyArg<A>) => Effect<A> = core.sync
/**
* @since 2.0.0
* @category constructors
*/
export const unit: Effect<void> = core.unit
/**
* @since 2.0.0
* @category constructors
*/
export const yieldNow: (options?: {
readonly priority?: number | undefined
}) => Effect<void> = core.yieldNow
// -------------------------------------------------------------------------------------
// error handling
// -------------------------------------------------------------------------------------
const _catch: {
<N extends keyof E, K extends E[N] & string, E, A1, E1, R1>(
discriminator: N,
options: { readonly failure: K; readonly onFailure: (error: Extract<E, { [n in N]: K }>) => Effect<A1, E1, R1> }
): <A, R>(self: Effect<A, E, R>) => Effect<A1 | A, E1 | Exclude<E, { [n in N]: K }>, R1 | R>
<A, E, R, N extends keyof E, K extends E[N] & string, A1, E1, R1>(
self: Effect<A, E, R>,
discriminator: N,
options: { readonly failure: K; readonly onFailure: (error: Extract<E, { [n in N]: K }>) => Effect<A1, E1, R1> }
): Effect<A | A1, E1 | Exclude<E, { [n in N]: K }>, R | R1>
} = effect._catch
export {
/**
* Recovers from specified error.
*
* @since 2.0.0
* @category error handling
*/
_catch as catch
}
/**
* Recovers from all recoverable errors.
*
* **Note**: that `Effect.catchAll` will not recover from unrecoverable defects. To
* recover from both recoverable and unrecoverable errors use
* `Effect.catchAllCause`.
*
* @since 2.0.0
* @category error handling
*/
export const catchAll: {
<E, A2, E2, R2>(f: (e: E) => Effect<A2, E2, R2>): <A, R>(self: Effect<A, E, R>) => Effect<A2 | A, E2, R2 | R>
<A, E, R, A2, E2, R2>(self: Effect<A, E, R>, f: (e: E) => Effect<A2, E2, R2>): Effect<A2 | A, E2, R2 | R>
} = core.catchAll
/**
* Recovers from both recoverable and unrecoverable errors.
*
* See `sandbox`, `mapErrorCause` for other functions that can
* recover from defects.
*
* @since 2.0.0
* @category error handling
*/
export const catchAllCause: {
<E, A2, E2, R2>(
f: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>
): <A, R>(self: Effect<A, E, R>) => Effect<A2 | A, E2, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
f: (cause: Cause.Cause<E>) => Effect<A2, E2, R2>
): Effect<A | A2, E2, R | R2>
} = core.catchAllCause
/**
* Recovers from all defects with provided function.
*
* **WARNING**: There is no sensible way to recover from defects. This
* method should be used only at the boundary between Effect and an external
* system, to transmit information on a defect for diagnostic or explanatory
* purposes.
*
* @since 2.0.0
* @category error handling
*/
export const catchAllDefect: {
<A2, E2, R2>(
f: (defect: unknown) => Effect<A2, E2, R2>
): <A, E, R>(self: Effect<A, E, R>) => Effect<A2 | A, E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
f: (defect: unknown) => Effect<A2, E2, R2>
): Effect<A | A2, E | E2, R | R2>
} = effect.catchAllDefect
/**
* Recovers from errors that match the given predicate.
*
* @since 2.0.0
* @category error handling
*/
export const catchIf: {
<E, EB extends E, A2, E2, R2>(
refinement: Refinement<NoInfer<E>, EB>,
f: (e: EB) => Effect<A2, E2, R2>
): <A, R>(self: Effect<A, E, R>) => Effect<A2 | A, E2 | Exclude<E, EB>, R2 | R>
<E, A2, E2, R2>(
predicate: Predicate<NoInfer<E>>,
f: (e: NoInfer<E>) => Effect<A2, E2, R2>
): <A, R>(self: Effect<A, E, R>) => Effect<A2 | A, E | E2, R2 | R>
<A, E, R, EB extends E, A2, E2, R2>(
self: Effect<A, E, R>,
refinement: Refinement<E, EB>,
f: (e: EB) => Effect<A2, E2, R2>
): Effect<A | A2, E2 | Exclude<E, EB>, R | R2>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
predicate: Predicate<E>,
f: (e: E) => Effect<A2, E2, R2>
): Effect<A | A2, E | E2, R | R2>
} = core.catchIf
/**
* Recovers from some or all of the error cases.
*
* @since 2.0.0
* @category error handling
*/
export const catchSome: {
<E, A2, E2, R2>(
pf: (e: NoInfer<E>) => Option.Option<Effect<A2, E2, R2>>
): <A, R>(self: Effect<A, E, R>) => Effect<A2 | A, E | E2, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
pf: (e: NoInfer<E>) => Option.Option<Effect<A2, E2, R2>>
): Effect<A | A2, E | E2, R | R2>
} = core.catchSome
/**
* Recovers from some or all of the error cases with provided cause.
*
* @since 2.0.0
* @category error handling
*/
export const catchSomeCause: {
<E, A2, E2, R2>(
f: (cause: Cause.Cause<NoInfer<E>>) => Option.Option<Effect<A2, E2, R2>>
): <A, R>(self: Effect<A, E, R>) => Effect<A2 | A, E | E2, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
f: (cause: Cause.Cause<NoInfer<E>>) => Option.Option<Effect<A2, E2, R2>>
): Effect<A2 | A, E | E2, R2 | R>
} = effect.catchSomeCause
/**
* Recovers from some or all of the defects with provided partial function.
*
* **WARNING**: There is no sensible way to recover from defects. This
* method should be used only