<E>(cause: Cause<E>): <A>(self: Enqueue<A, E>) => Effect<boolean>
<A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>Fails the queue with a cause. If the queue is already done, false is
returned.
Example (Failing queues with a cause)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, string>(10)
// Create a cause and fail the queue
const cause = Cause.fail("Queue processing failed")
const failed = yield* Queue.failCause(queue, cause)
console.log(failed) // true
// The queue is now done with the specified failure cause
console.log(queue.state._tag) // "Done"
})export const const failCause: {
<E>(cause: Cause<E>): <A>(
self: Enqueue<A, E>
) => Effect<boolean>
<A, E>(
self: Enqueue<A, E>,
cause: Cause<E>
): Effect<boolean>
}
Fails the queue with a cause. If the queue is already done, false is
returned.
Example (Failing queues with a cause)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, string>(10)
// Create a cause and fail the queue
const cause = Cause.fail("Queue processing failed")
const failed = yield* Queue.failCause(queue, cause)
console.log(failed) // true
// The queue is now done with the specified failure cause
console.log(queue.state._tag) // "Done"
})
failCause: {
<function (type parameter) E in <E>(cause: Cause<E>): <A>(self: Enqueue<A, E>) => Effect<boolean>E>(cause: Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause: interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
isInterruptReason
.
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <E>(cause: Cause<E>): <A>(self: Enqueue<A, E>) => Effect<boolean>E>): <function (type parameter) A in <A>(self: Enqueue<A, E>): Effect<boolean>A>(self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self: interface Enqueue<in A, in E = never>An Enqueue is a queue that can be offered to.
Details
This interface represents the write-only part of a Queue, allowing you to offer
elements to the queue but not take elements from it.
Example (Offering through enqueue handles)
import { Effect, Queue } from "effect"
// Function that only needs write access to a queue
const producer = (enqueue: Queue.Enqueue<string>) =>
Effect.gen(function*() {
yield* Queue.offer(enqueue, "hello")
yield* Queue.offerAll(enqueue, ["world", "!"])
})
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string>(10)
yield* producer(queue)
})
Companion namespace containing type-level metadata for the Enqueue
write-only queue interface.
Enqueue<function (type parameter) A in <A>(self: Enqueue<A, E>): Effect<boolean>A, function (type parameter) E in <E>(cause: Cause<E>): <A>(self: Enqueue<A, E>) => Effect<boolean>E>) => 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) A in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>A, function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>E>(self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self: interface Enqueue<in A, in E = never>An Enqueue is a queue that can be offered to.
Details
This interface represents the write-only part of a Queue, allowing you to offer
elements to the queue but not take elements from it.
Example (Offering through enqueue handles)
import { Effect, Queue } from "effect"
// Function that only needs write access to a queue
const producer = (enqueue: Queue.Enqueue<string>) =>
Effect.gen(function*() {
yield* Queue.offer(enqueue, "hello")
yield* Queue.offerAll(enqueue, ["world", "!"])
})
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string>(10)
yield* producer(queue)
})
Companion namespace containing type-level metadata for the Enqueue
write-only queue interface.
Enqueue<function (type parameter) A in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>A, function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>E>, cause: Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause: interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
isInterruptReason
.
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>E>): 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, <A, E>(self: Enqueue<A, E>, cause: Cause<E>) => Effect<boolean>>(arity: 2, body: <A, E>(self: Enqueue<A, E>, cause: Cause<E>) => Effect<boolean>): ((...args: Array<any>) => any) & (<A, E>(self: Enqueue<A, E>, cause: Cause<E>) => 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(
2,
<function (type parameter) A in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>A, function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>E>(self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self: interface Enqueue<in A, in E = never>An Enqueue is a queue that can be offered to.
Details
This interface represents the write-only part of a Queue, allowing you to offer
elements to the queue but not take elements from it.
Example (Offering through enqueue handles)
import { Effect, Queue } from "effect"
// Function that only needs write access to a queue
const producer = (enqueue: Queue.Enqueue<string>) =>
Effect.gen(function*() {
yield* Queue.offer(enqueue, "hello")
yield* Queue.offerAll(enqueue, ["world", "!"])
})
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string>(10)
yield* producer(queue)
})
Companion namespace containing type-level metadata for the Enqueue
write-only queue interface.
Enqueue<function (type parameter) A in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>A, function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>E>, cause: Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause: interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
isInterruptReason
.
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<function (type parameter) E in <A, E>(self: Enqueue<A, E>, cause: Cause<E>): Effect<boolean>E>): 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 internalEffectinternalEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect.Effect<A>
sync(() => const failCauseUnsafe: <A, E>(
self: Enqueue<A, E>,
cause: Cause<E>
) => boolean
Fails the queue with a cause synchronously. If the queue is already done, false is
returned.
When to use
Use when queue completion must be driven from synchronous internals while
preserving the full failure Cause.
Gotchas
This is an unsafe operation that directly modifies the queue without Effect wrapping.
Example (Failing queues with a cause synchronously)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, string>(10)
// Create a cause and fail the queue synchronously
const cause = Cause.fail("Processing error")
const failed = Queue.failCauseUnsafe(queue, cause)
console.log(failed) // true
// The queue is now done with the specified failure cause
console.log(queue.state._tag) // "Done"
})
failCauseUnsafe(self: Enqueue<A, E>(parameter) self: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
self, cause: Cause<E>(parameter) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause))
)