<A = never>(): Effect.Effect<TxChunk<A>>Creates a new empty TxChunk.
Details
This function returns a new TxChunk reference that is initially empty. No existing TxChunk instances are modified.
Example (Creating an empty TxChunk)
import { Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create an empty TxChunk
const txChunk = yield* TxChunk.empty<number>()
// Check if it's empty - automatically transactional
const isEmpty = yield* TxChunk.isEmpty(txChunk)
console.log(isEmpty) // true
// Add elements - automatically transactional
yield* TxChunk.append(txChunk, 42)
const isStillEmpty = yield* TxChunk.isEmpty(txChunk)
console.log(isStillEmpty) // false
})export const const empty: <
A = never
>() => Effect.Effect<TxChunk<A>>
Creates a new empty TxChunk.
Details
This function returns a new TxChunk reference that is initially empty. No existing TxChunk
instances are modified.
Example (Creating an empty TxChunk)
import { Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create an empty TxChunk
const txChunk = yield* TxChunk.empty<number>()
// Check if it's empty - automatically transactional
const isEmpty = yield* TxChunk.isEmpty(txChunk)
console.log(isEmpty) // true
// Add elements - automatically transactional
yield* TxChunk.append(txChunk, 42)
const isStillEmpty = yield* TxChunk.isEmpty(txChunk)
console.log(isStillEmpty) // false
})
empty = <function (type parameter) A in <A = never>(): Effect.Effect<TxChunk<A>>A = never>(): 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 TxChunk<in out A>TxChunk is a transactional chunk data structure that provides Software Transactional Memory (STM)
semantics for chunk operations.
Details
Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
calls Effect.txRetry and any of the accessed TxChunk values change.
Example (Using a transactional chunk)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create a transactional chunk
const txChunk: TxChunk.TxChunk<number> = yield* TxChunk.fromIterable([
1,
2,
3
])
// Single operations - no explicit transaction needed
yield* TxChunk.append(txChunk, 4)
const result = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4]
// Multi-step atomic operation - use explicit transaction
yield* Effect.tx(
Effect.gen(function*() {
yield* TxChunk.prepend(txChunk, 0)
yield* TxChunk.append(txChunk, 5)
})
)
const finalResult = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(finalResult)) // [0, 1, 2, 3, 4, 5]
})
TxChunk<function (type parameter) A in <A = never>(): Effect.Effect<TxChunk<A>>A>> =>
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 TxRefTxRef.const make: <Chunk.Chunk<A>>(initial: Chunk.Chunk<A>) => Effect.Effect<TxRef.TxRef<Chunk.Chunk<A>>, never, never>Creates a new TxRef with the specified initial value.
When to use
Use to create a TxRef inside an Effect workflow.
Example (Creating transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
// Create a transactional reference with initial value
const counter = yield* TxRef.make(0)
const name = yield* TxRef.make("Alice")
// Use in transactions
yield* Effect.tx(Effect.gen(function*() {
yield* TxRef.set(counter, 42)
yield* TxRef.set(name, "Bob")
}))
console.log(yield* TxRef.get(counter)) // 42
console.log(yield* TxRef.get(name)) // "Bob"
})
make(import ChunkChunk.const empty: <A = never>() => Chunk<A>Creates an empty Chunk.
Example (Creating an empty chunk)
import { Chunk } from "effect"
const emptyChunk = Chunk.empty()
console.log(Chunk.size(emptyChunk)) // 0
empty<function (type parameter) A in <A = never>(): Effect.Effect<TxChunk<A>>A>()), (ref: TxRef.TxRef<Chunk.Chunk<A>>(parameter) ref: {
version: number;
pending: Map<unknown, () => void>;
value: 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; <…;
}
ref) => const makeUnsafe: <A>(
ref: TxRef.TxRef<Chunk.Chunk<A>>
) => TxChunk<A>
Creates a new TxChunk with the specified TxRef.
Details
This function returns a new TxChunk reference wrapping the provided TxRef. No existing TxChunk
instances are modified.
Example (Wrapping an existing TxRef)
import { Chunk, TxChunk, TxRef } from "effect"
// Create a TxChunk from an existing TxRef (advanced usage)
const ref = TxRef.makeUnsafe(Chunk.fromIterable([1, 2, 3]))
const txChunk = TxChunk.makeUnsafe(ref)
makeUnsafe(ref: TxRef.TxRef<Chunk.Chunk<A>>(parameter) ref: {
version: number;
pending: Map<unknown, () => void>;
value: 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; <…;
}
ref))