<A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<
Resource<A, E>,
never,
Scope.Scope | R
>Creates a Resource that must be refreshed manually.
When to use
Use when you need manual control over resource refresh timing rather than an automatic schedule.
export const const manual: <A, E, R>(
acquire: Effect.Effect<A, E, R>
) => Effect.Effect<
Resource<A, E>,
never,
Scope.Scope | R
>
Creates a Resource that must be refreshed manually.
When to use
Use when you need manual control over resource refresh timing rather than an
automatic schedule.
manual = <function (type parameter) A in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>A, function (type parameter) E in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>E, function (type parameter) R in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>R>(
acquire: Effect.Effect<A, E, R>(parameter) acquire: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
acquire: import EffectEffect.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) A in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>A, function (type parameter) E in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>E, function (type parameter) R in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>R>
): import EffectEffect.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<interface Resource<in out A, in out E = never>A Resource is a value loaded into memory that can be refreshed manually or
automatically according to a schedule.
When to use
Use to model a scoped value whose latest acquisition result is kept available
for repeated reads and can be refreshed manually or on a schedule.
Resource<function (type parameter) A in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>A, function (type parameter) E in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>E>, never, import ScopeScope.Scope | function (type parameter) R in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>R> =>
import EffectEffect.const contextWith: <R, A, E, R2>(
f: (
context: Context.Context<R>
) => Effect<A, E, R2>
) => Effect<A, E, R | R2>
Transforms the current context using the provided function.
When to use
Use to derive an effect from the complete Context.
Details
This function allows you to access the complete context and perform
computations based on all available services. This is useful when you need
to conditionally execute logic based on what services are available.
Example (Deriving values from the context)
import { Console, Context, Effect, Option } from "effect"
const Logger = Context.Service<{
log: (msg: string) => void
}>("Logger")
const Cache = Context.Service<{
get: (key: string) => string | null
}>("Cache")
const program = Effect.contextWith((services) => {
const cacheOption = Context.getOption(services, Cache)
const hasCache = Option.isSome(cacheOption)
if (hasCache) {
return Effect.gen(function*() {
const cache = yield* Effect.service(Cache)
yield* Console.log("Using cached data")
return cache.get("user:123") || "default"
})
} else {
return Effect.gen(function*() {
yield* Console.log("No cache available, using fallback")
return "fallback data"
})
}
})
const withCache = Effect.provideService(program, Cache, {
get: () => "cached_value"
})
contextWith((context: Context.Context<R>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
context: import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<function (type parameter) R in <A, E, R>(acquire: Effect.Effect<A, E, R>): Effect.Effect<Resource<A, E>, never, Scope.Scope | R>R>) => {
const const providedAcquire: Effect.Effect<
A,
E,
never
>
const providedAcquire: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
providedAcquire = import EffectEffect.const updateContext: {
<R2, R>(
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): <A, E>(
self: Effect<A, E, R>
) => Effect<A, E, R2>
<A, E, R, R2>(
self: Effect<A, E, R>,
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): Effect<A, E, R2>
}
updateContext(
acquire: Effect.Effect<A, E, R>(parameter) acquire: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
acquire,
(input: Context.Context<never>(parameter) input: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
input: import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<never>) => import ContextContext.const merge: {
<R1>(that: Context<R1>): <Services>(
self: Context<Services>
) => Context<R1 | Services>
<Services, R1>(
self: Context<Services>,
that: Context<R1>
): Context<Services | R1>
}
merge(context: Context.Context<R>(parameter) context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
context, input: Context.Context<never>(parameter) input: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
input)
)
return import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map(
import ScopedRefScopedRef.const fromAcquire: <A, E, R>(
acquire: Effect.Effect<A, E, R>
) => Effect.Effect<
ScopedRef<A>,
E,
Scope.Scope | R
>
Creates a new ScopedRef from an effect that acquires the initial value.
When to use
Use when creating a ScopedRef whose initial value requires acquiring
resources that must be released.
fromAcquire(import EffectEffect.const exit: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Exit.Exit<A, E>, never, R>
Transforms an effect to encapsulate both failure and success using the Exit
data type.
When to use
Use when you need to inspect the full outcome, including typed failures, defects,
and interruptions.
Details
exit wraps an effect's success or failure inside an Exit type, allowing
you to handle both cases explicitly.
The resulting effect cannot fail because the failure is encapsulated within
the Exit.Failure type. The error type is set to never, indicating that
the effect is structured to never fail directly.
Example (Capturing completion as Exit)
import { Effect } from "effect"
const success = Effect.succeed(42)
const failure = Effect.fail("Something went wrong")
const program1 = Effect.exit(success)
const program2 = Effect.exit(failure)
Effect.runPromise(program1).then(console.log)
// { _id: 'Exit', _tag: 'Success', value: 42 }
Effect.runPromise(program2).then(console.log)
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
exit(const providedAcquire: Effect.Effect<
A,
E,
never
>
const providedAcquire: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
providedAcquire)),
(scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>(parameter) scopedRef: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
scopedRef) => const makeUnsafe: <A, E>(
scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>,
acquire: Effect.Effect<A, E>
) => Resource<A, E>
makeUnsafe(scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>(parameter) scopedRef: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, A]>;
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; <…;
}
scopedRef, const providedAcquire: Effect.Effect<
A,
E,
never
>
const providedAcquire: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
providedAcquire)
)
})