Package: effect
Module: TxChunk
Creates a new TxChunk from an iterable.
Details
This function returns a new TxChunk reference containing elements from the provided iterable. No existing TxChunk instances are modified.
Example (Creating from an iterable)
import { Chunk, Effect, TxChunk } from "effect"
const program = Effect.gen(function*() {
// Create TxChunk from array
const txChunk = yield* TxChunk.fromIterable([1, 2, 3, 4, 5])
// Read the contents - automatically transactional
const chunk = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(chunk)) // [1, 2, 3, 4, 5]
// Multi-step atomic modification - use explicit transaction
yield* Effect.tx(
Effect.gen(function*() {
yield* TxChunk.append(txChunk, 6)
yield* TxChunk.prepend(txChunk, 0)
})
)
const updated = yield* TxChunk.get(txChunk)
console.log(Chunk.toReadonlyArray(updated)) // [0, 1, 2, 3, 4, 5, 6]
})
Signature
declare const fromIterable: <A>(iterable: Iterable<A>) => Effect.Effect<TxChunk<A>>
Since v4.0.0