<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.type Effect.Effect = /*unresolved*/ anyEffect<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.map(import TxRefTxRef.const make: <any>(initial: any) => anyCreates 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.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))