<Key, A>(key: Key, f: Predicate<A>): <E, R>(
self: Cache<Key, A, E, R>
) => Effect.Effect<boolean>
<Key, A, E, R>(
self: Cache<Key, A, E, R>,
key: Key,
f: Predicate<A>
): Effect.Effect<boolean>Invalidates the entry associated with the specified key in the cache when the predicate returns true for the cached value.
Example (Invalidating entries conditionally)
import { Cache, Effect } from "effect"
const program = Effect.gen(function*() {
const cache = yield* Cache.make({
capacity: 10,
lookup: (key: string) => Effect.succeed(key.length)
})
// Add values to the cache
yield* Cache.get(cache, "hello") // value = 5
yield* Cache.get(cache, "hi") // value = 2
// Invalidate when value equals 5
const invalidated1 = yield* Cache.invalidateWhen(
cache,
"hello",
(value) => value === 5
)
console.log(invalidated1) // true
console.log(yield* Cache.has(cache, "hello")) // false
// Don't invalidate when predicate doesn't match
const invalidated2 = yield* Cache.invalidateWhen(
cache,
"hi",
(value) => value === 5
)
console.log(invalidated2) // false
console.log(yield* Cache.has(cache, "hi")) // true (still present)
// Returns false for non-existent keys
const invalidated3 = yield* Cache.invalidateWhen(
cache,
"nonexistent",
() => true
)
console.log(invalidated3) // false
// Returns false for failed cached values
const cacheWithErrors = yield* Cache.make<string, number, string>({
capacity: 10,
lookup: (key: string) =>
key === "fail" ? Effect.fail("error") : Effect.succeed(key.length)
})
yield* Effect.exit(Cache.get(cacheWithErrors, "fail"))
const invalidated4 = yield* Cache.invalidateWhen(
cacheWithErrors,
"fail",
() => true
)
console.log(invalidated4) // false (can't invalidate failed values)
})export const const invalidateWhen: {
<Key, A>(key: Key, f: Predicate<A>): <E, R>(
self: Cache<Key, A, E, R>
) => Effect.Effect<boolean>
<Key, A, E, R>(
self: Cache<Key, A, E, R>,
key: Key,
f: Predicate<A>
): Effect.Effect<boolean>
}
Invalidates the entry associated with the specified key in the cache when the
predicate returns true for the cached value.
Example (Invalidating entries conditionally)
import { Cache, Effect } from "effect"
const program = Effect.gen(function*() {
const cache = yield* Cache.make({
capacity: 10,
lookup: (key: string) => Effect.succeed(key.length)
})
// Add values to the cache
yield* Cache.get(cache, "hello") // value = 5
yield* Cache.get(cache, "hi") // value = 2
// Invalidate when value equals 5
const invalidated1 = yield* Cache.invalidateWhen(
cache,
"hello",
(value) => value === 5
)
console.log(invalidated1) // true
console.log(yield* Cache.has(cache, "hello")) // false
// Don't invalidate when predicate doesn't match
const invalidated2 = yield* Cache.invalidateWhen(
cache,
"hi",
(value) => value === 5
)
console.log(invalidated2) // false
console.log(yield* Cache.has(cache, "hi")) // true (still present)
// Returns false for non-existent keys
const invalidated3 = yield* Cache.invalidateWhen(
cache,
"nonexistent",
() => true
)
console.log(invalidated3) // false
// Returns false for failed cached values
const cacheWithErrors = yield* Cache.make<string, number, string>({
capacity: 10,
lookup: (key: string) =>
key === "fail" ? Effect.fail("error") : Effect.succeed(key.length)
})
yield* Effect.exit(Cache.get(cacheWithErrors, "fail"))
const invalidated4 = yield* Cache.invalidateWhen(
cacheWithErrors,
"fail",
() => true
)
console.log(invalidated4) // false (can't invalidate failed values)
})
invalidateWhen: {
<function (type parameter) Key in <Key, A>(key: Key, f: Predicate<A>): <E, R>(self: Cache<Key, A, E, R>) => Effect.Effect<boolean>Key, function (type parameter) A in <Key, A>(key: Key, f: Predicate<A>): <E, R>(self: Cache<Key, A, E, R>) => Effect.Effect<boolean>A>(key: Keykey: function (type parameter) Key in <Key, A>(key: Key, f: Predicate<A>): <E, R>(self: Cache<Key, A, E, R>) => Effect.Effect<boolean>Key, f: Predicate<A>f: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <Key, A>(key: Key, f: Predicate<A>): <E, R>(self: Cache<Key, A, E, R>) => Effect.Effect<boolean>A>): <function (type parameter) E in <E, R>(self: Cache<Key, A, E, R>): Effect.Effect<boolean>E, function (type parameter) R in <E, R>(self: Cache<Key, A, E, R>): Effect.Effect<boolean>R>(self: Cache<Key, A, E, R>(parameter) self: {
map: MutableHashMap.MutableHashMap<Key, Entry<A, E>>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
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; <…;
}
self: interface Cache<in out Key, in out A, in out E = never, out R = never>A cache interface that provides a mutable key-value store with automatic TTL management,
capacity limits, and lookup functions for cache misses.
Example (Creating a basic cache)
import { Cache, Effect } from "effect"
// Basic cache with string keys and number values
const program = Effect.gen(function*() {
const cache = yield* Cache.make<string, number>({
capacity: 100,
lookup: (key: string) => Effect.succeed(key.length)
})
// Cache operations
const value1 = yield* Cache.get(cache, "hello") // 5
const value2 = yield* Cache.get(cache, "world") // 5
const value3 = yield* Cache.get(cache, "hello") // 5 (cached)
return [value1, value2, value3]
})
Example (Handling lookup failures)
import { Cache, Effect } from "effect"
// Cache with error handling
const program = Effect.gen(function*() {
const cache = yield* Cache.make<string, number, string>({
capacity: 10,
lookup: (key: string) =>
key === "error"
? Effect.fail("Lookup failed")
: Effect.succeed(key.length)
})
// Handle successful and failed lookups
const success = yield* Cache.get(cache, "test") // 4
const failure = yield* Effect.exit(Cache.get(cache, "error")) // Exit.fail
return { success, failure }
})
Example (Using complex keys with TTL)
import { Cache, Data, Duration, Effect } from "effect"
// Cache with complex key types and TTL
class UserId extends Data.Class<{ id: number }> {}
const program = Effect.gen(function*() {
const userCache = yield* Cache.make<UserId, string>({
capacity: 1000,
lookup: (userId: UserId) => Effect.succeed(`User-${userId.id}`),
timeToLive: Duration.minutes(5)
})
const userId = new UserId({ id: 123 })
const userName = yield* Cache.get(userCache, userId)
return userName // "User-123"
})
Cache<function (type parameter) Key in <Key, A>(key: Key, f: Predicate<A>): <E, R>(self: Cache<Key, A, E, R>) => Effect.Effect<boolean>Key, function (type parameter) A in <Key, A>(key: Key, f: Predicate<A>): <E, R>(self: Cache<Key, A, E, R>) => Effect.Effect<boolean>A, function (type parameter) E in <E, R>(self: Cache<Key, A, E, R>): Effect.Effect<boolean>E, function (type parameter) R in <E, R>(self: Cache<Key, A, E, R>): Effect.Effect<boolean>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<boolean>
<function (type parameter) Key in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>R>(self: Cache<Key, A, E, R>(parameter) self: {
map: MutableHashMap.MutableHashMap<Key, Entry<A, E>>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
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; <…;
}
self: interface Cache<in out Key, in out A, in out E = never, out R = never>A cache interface that provides a mutable key-value store with automatic TTL management,
capacity limits, and lookup functions for cache misses.
Example (Creating a basic cache)
import { Cache, Effect } from "effect"
// Basic cache with string keys and number values
const program = Effect.gen(function*() {
const cache = yield* Cache.make<string, number>({
capacity: 100,
lookup: (key: string) => Effect.succeed(key.length)
})
// Cache operations
const value1 = yield* Cache.get(cache, "hello") // 5
const value2 = yield* Cache.get(cache, "world") // 5
const value3 = yield* Cache.get(cache, "hello") // 5 (cached)
return [value1, value2, value3]
})
Example (Handling lookup failures)
import { Cache, Effect } from "effect"
// Cache with error handling
const program = Effect.gen(function*() {
const cache = yield* Cache.make<string, number, string>({
capacity: 10,
lookup: (key: string) =>
key === "error"
? Effect.fail("Lookup failed")
: Effect.succeed(key.length)
})
// Handle successful and failed lookups
const success = yield* Cache.get(cache, "test") // 4
const failure = yield* Effect.exit(Cache.get(cache, "error")) // Exit.fail
return { success, failure }
})
Example (Using complex keys with TTL)
import { Cache, Data, Duration, Effect } from "effect"
// Cache with complex key types and TTL
class UserId extends Data.Class<{ id: number }> {}
const program = Effect.gen(function*() {
const userCache = yield* Cache.make<UserId, string>({
capacity: 1000,
lookup: (userId: UserId) => Effect.succeed(`User-${userId.id}`),
timeToLive: Duration.minutes(5)
})
const userId = new UserId({ id: 123 })
const userName = yield* Cache.get(userCache, userId)
return userName // "User-123"
})
Cache<function (type parameter) Key in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>R>, key: Keykey: function (type parameter) Key in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>Key, f: Predicate<A>f: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>A>): 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<boolean>
} = dual<(...args: Array<any>) => any, <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>) => Effect.Effect<boolean>>(arity: 3, body: <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>) => Effect.Effect<boolean>): ((...args: Array<any>) => any) & (<Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>) => Effect.Effect<boolean>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
3,
<function (type parameter) Key in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>R>(self: Cache<Key, A, E, R>(parameter) self: {
map: MutableHashMap.MutableHashMap<Key, Entry<A, E>>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
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; <…;
}
self: interface Cache<in out Key, in out A, in out E = never, out R = never>A cache interface that provides a mutable key-value store with automatic TTL management,
capacity limits, and lookup functions for cache misses.
Example (Creating a basic cache)
import { Cache, Effect } from "effect"
// Basic cache with string keys and number values
const program = Effect.gen(function*() {
const cache = yield* Cache.make<string, number>({
capacity: 100,
lookup: (key: string) => Effect.succeed(key.length)
})
// Cache operations
const value1 = yield* Cache.get(cache, "hello") // 5
const value2 = yield* Cache.get(cache, "world") // 5
const value3 = yield* Cache.get(cache, "hello") // 5 (cached)
return [value1, value2, value3]
})
Example (Handling lookup failures)
import { Cache, Effect } from "effect"
// Cache with error handling
const program = Effect.gen(function*() {
const cache = yield* Cache.make<string, number, string>({
capacity: 10,
lookup: (key: string) =>
key === "error"
? Effect.fail("Lookup failed")
: Effect.succeed(key.length)
})
// Handle successful and failed lookups
const success = yield* Cache.get(cache, "test") // 4
const failure = yield* Effect.exit(Cache.get(cache, "error")) // Exit.fail
return { success, failure }
})
Example (Using complex keys with TTL)
import { Cache, Data, Duration, Effect } from "effect"
// Cache with complex key types and TTL
class UserId extends Data.Class<{ id: number }> {}
const program = Effect.gen(function*() {
const userCache = yield* Cache.make<UserId, string>({
capacity: 1000,
lookup: (userId: UserId) => Effect.succeed(`User-${userId.id}`),
timeToLive: Duration.minutes(5)
})
const userId = new UserId({ id: 123 })
const userName = yield* Cache.get(userCache, userId)
return userName // "User-123"
})
Cache<function (type parameter) Key in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>R>, key: Keykey: function (type parameter) Key in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>Key, f: Predicate<A>f: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <Key, A, E, R>(self: Cache<Key, A, E, R>, key: Key, f: Predicate<A>): Effect.Effect<boolean>A>): 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<boolean> =>
import corecore.const withFiber: <
A,
E = never,
R = never
>(
evaluate: (
fiber: FiberImpl<unknown, unknown>
) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
withFiber((fiber: effect.FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit.Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit.Exit<unknown, unknown> | undefined;
evaluate: (effect: core.Primitive) => void;
runLoop: (effect: core.Primitive) => typeof core.Yield | Exit.Exit<unknown, unknown>;
getCont: <S extends core.contA | core.contE>(symbol: S) => (core.Primitive & Record<S, (value: any, fiber: effect.FiberImpl) => core.Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => core.Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber) => {
const const oentry: Entry<A, E> | undefinedoentry = const getImpl: <Key, A, E, R>(
self: Cache<Key, A, E, R>,
key: Key,
fiber: Fiber.Fiber<any, any>,
isRead?: boolean
) => Entry<A, E> | undefined
getImpl(self: Cache<Key, A, E, R>(parameter) self: {
map: MutableHashMap.MutableHashMap<Key, Entry<A, E>>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
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; <…;
}
self, key: Keykey, fiber: effect.FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit.Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit.Exit<unknown, unknown> | undefined;
evaluate: (effect: core.Primitive) => void;
runLoop: (effect: core.Primitive) => typeof core.Yield | Exit.Exit<unknown, unknown>;
getCont: <S extends core.contA | core.contE>(symbol: S) => (core.Primitive & Record<S, (value: any, fiber: effect.FiberImpl) => core.Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => core.Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber, false)
if (const oentry: Entry<A, E> | undefinedoentry === var undefinedundefined) {
return import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(false)
}
return import DeferredDeferred.await<A, E>(self: Deferred<A, E>): Effect<A, E>Retrieves the value of the Deferred, suspending the fiber running the
workflow until the result is available.
When to use
Use to wait for a Deferred to be completed and resume with its success,
failure, defect, or interruption.
Details
Awaiters observe the completion effect stored in the Deferred.
Example (Awaiting a Deferred value)
import { Deferred, Effect } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* Deferred.make<number>()
yield* Deferred.succeed(deferred, 42)
const value = yield* Deferred.await(deferred)
console.log(value) // 42
})
await(const oentry: Entry<A, E>const oentry: {
expiresAt: number | undefined;
deferred: Deferred.Deferred<A, E>;
}
oentry.Entry<A, E>.deferred: Deferred.Deferred<A, E>(property) Entry<A, E>.deferred: {
effect: Effect<A, E>;
resumes: Array<(effect: Effect<A, E>) => void> | undefined;
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; <…;
}
deferred).Pipeable.pipe<Effect.Effect<A, E, never>, Effect.Effect<boolean, E, never>, Effect.Effect<boolean, never, never>>(this: Effect.Effect<A, E, never>, ab: (_: Effect.Effect<A, E, never>) => Effect.Effect<boolean, E, never>, bc: (_: Effect.Effect<boolean, E, never>) => Effect.Effect<boolean, never, never>): Effect.Effect<boolean, never, never> (+21 overloads)pipe(
import effecteffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E, R>
<A, E, R, B>(
self: Effect.Effect<A, E, R>,
f: (a: A) => B
): Effect.Effect<B, E, R>
}
map((value: Avalue) => {
if (f: Predicate<A>f(value: Avalue)) {
import MutableHashMapMutableHashMap.const remove: {
<K>(key: K): <V>(
self: MutableHashMap<K, V>
) => MutableHashMap<K, V>
<K, V>(
self: MutableHashMap<K, V>,
key: K
): MutableHashMap<K, V>
}
remove(self: Cache<Key, A, E, R>(parameter) self: {
map: MutableHashMap.MutableHashMap<Key, Entry<A, E>>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
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; <…;
}
self.Cache<Key, A, E, R>.map: MutableHashMap.MutableHashMap<Key, Entry<A, E>>(property) Cache<Key, A, E, R>.map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map, key: Keykey)
return true
}
return false
}),
import effecteffect.const catchCause: {
<E, B, E2, R2>(
f: (
cause: NoInfer<Cause.Cause<E>>
) => Effect.Effect<B, E2, R2>
): <A, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A | B, E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect.Effect<A, E, R>,
f: (
cause: NoInfer<Cause.Cause<E>>
) => Effect.Effect<B, E2, R2>
): Effect.Effect<A | B, E2, R | R2>
}
catchCause(() => import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(false))
)
})
)