<A>(value: A): <E>(self: TxDeferred<A, E>) => Effect.Effect<boolean>
<A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>Completes the deferred with a success value. Returns true if this was the
first completion, false if already completed.
When to use
Use to complete a TxDeferred with a successful value.
Example (Completing with a success value)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
const first = yield* TxDeferred.succeed(deferred, 42)
console.log(first) // true
const second = yield* TxDeferred.succeed(deferred, 99)
console.log(second) // false
})export const const succeed: {
<A>(value: A): <E>(
self: TxDeferred<A, E>
) => Effect.Effect<boolean>
<A, E>(
self: TxDeferred<A, E>,
value: A
): Effect.Effect<boolean>
}
Completes the deferred with a success value. Returns true if this was the
first completion, false if already completed.
When to use
Use to complete a TxDeferred with a successful value.
Example (Completing with a success value)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
const first = yield* TxDeferred.succeed(deferred, 42)
console.log(first) // true
const second = yield* TxDeferred.succeed(deferred, 99)
console.log(second) // false
})
succeed: {
<function (type parameter) A in <A>(value: A): <E>(self: TxDeferred<A, E>) => Effect.Effect<boolean>A>(value: Avalue: function (type parameter) A in <A>(value: A): <E>(self: TxDeferred<A, E>) => Effect.Effect<boolean>A): <function (type parameter) E in <E>(self: TxDeferred<A, E>): Effect.Effect<boolean>E>(self: TxDeferred<A, E>(parameter) self: {
ref: TxRef.TxRef<Option<Result<A, E>>>;
toString: () => string;
toJSON: () => unknown;
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 TxDeferred<in out A, in out E = never>A transactional deferred is a write-once cell readable within transactions.
Readers block (retry the transaction) until a value is committed, and writers
succeed only on the first call; subsequent writes return false.
When to use
Use to coordinate transaction-local readers and one-time completion with a
success or failure result.
Example (Completing a transactional deferred)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
// Complete the deferred
const first = yield* TxDeferred.succeed(deferred, 42)
console.log(first) // true
// Second write is a no-op
const second = yield* TxDeferred.succeed(deferred, 99)
console.log(second) // false
// Read the value
const value = yield* TxDeferred.await(deferred)
console.log(value) // 42
})
TxDeferred<function (type parameter) A in <A>(value: A): <E>(self: TxDeferred<A, E>) => Effect.Effect<boolean>A, function (type parameter) E in <E>(self: TxDeferred<A, E>): Effect.Effect<boolean>E>) => 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) A in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>E>(self: TxDeferred<A, E>(parameter) self: {
ref: TxRef.TxRef<Option<Result<A, E>>>;
toString: () => string;
toJSON: () => unknown;
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 TxDeferred<in out A, in out E = never>A transactional deferred is a write-once cell readable within transactions.
Readers block (retry the transaction) until a value is committed, and writers
succeed only on the first call; subsequent writes return false.
When to use
Use to coordinate transaction-local readers and one-time completion with a
success or failure result.
Example (Completing a transactional deferred)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
// Complete the deferred
const first = yield* TxDeferred.succeed(deferred, 42)
console.log(first) // true
// Second write is a no-op
const second = yield* TxDeferred.succeed(deferred, 99)
console.log(second) // false
// Read the value
const value = yield* TxDeferred.await(deferred)
console.log(value) // 42
})
TxDeferred<function (type parameter) A in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>E>, value: Avalue: function (type parameter) A in <A, E>(self: TxDeferred<A, E>, value: 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, <A, E>(self: TxDeferred<A, E>, value: A) => Effect.Effect<boolean>>(arity: 2, body: <A, E>(self: TxDeferred<A, E>, value: A) => Effect.Effect<boolean>): ((...args: Array<any>) => any) & (<A, E>(self: TxDeferred<A, E>, value: 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(
2,
<function (type parameter) A in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>E>(self: TxDeferred<A, E>(parameter) self: {
ref: TxRef.TxRef<Option<Result<A, E>>>;
toString: () => string;
toJSON: () => unknown;
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 TxDeferred<in out A, in out E = never>A transactional deferred is a write-once cell readable within transactions.
Readers block (retry the transaction) until a value is committed, and writers
succeed only on the first call; subsequent writes return false.
When to use
Use to coordinate transaction-local readers and one-time completion with a
success or failure result.
Example (Completing a transactional deferred)
import { Effect, TxDeferred } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* TxDeferred.make<number>()
// Complete the deferred
const first = yield* TxDeferred.succeed(deferred, 42)
console.log(first) // true
// Second write is a no-op
const second = yield* TxDeferred.succeed(deferred, 99)
console.log(second) // false
// Read the value
const value = yield* TxDeferred.await(deferred)
console.log(value) // 42
})
TxDeferred<function (type parameter) A in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean>E>, value: Avalue: function (type parameter) A in <A, E>(self: TxDeferred<A, E>, value: 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> => const done: {
<A, E>(result: Result<A, E>): (
self: TxDeferred<A, E>
) => Effect.Effect<boolean>
<A, E>(
self: TxDeferred<A, E>,
result: Result<A, E>
): Effect.Effect<boolean>
}
done(self: TxDeferred<A, E>(parameter) self: {
ref: TxRef.TxRef<Option<Result<A, E>>>;
toString: () => string;
toJSON: () => unknown;
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, import ResRes.const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(value: Avalue))
)