Hyperlinkv0.8.0-beta.28

TxChunk

TxChunk.concatconsteffect/TxChunk.ts:812
<A>(other: TxChunk<A>): (self: TxChunk<A>) => Effect.Effect<void>
<A>(self: TxChunk<A>, other: TxChunk<A>): Effect.Effect<void>

Concatenates another TxChunk to the end of this TxChunk.

Details

This function mutates the original TxChunk by appending all elements from the other TxChunk. It does not return a new TxChunk reference.

Example (Concatenating TxChunks)

import { Chunk, Effect, TxChunk } from "effect"

const program = Effect.gen(function*() {
  const txChunk1 = yield* TxChunk.fromIterable([1, 2, 3])
  const txChunk2 = yield* TxChunk.fromIterable([4, 5, 6])

  // Concatenate atomically within a transaction
  yield* TxChunk.concat(txChunk1, txChunk2)

  const result = yield* TxChunk.get(txChunk1)
  console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4, 5, 6]

  // Original txChunk2 is unchanged
  const original = yield* TxChunk.get(txChunk2)
  console.log(Chunk.toReadonlyArray(original)) // [4, 5, 6]
})
combinators
Source effect/TxChunk.ts:81211 lines
export const concat: {
  <A>(other: TxChunk<A>): (self: TxChunk<A>) => Effect.Effect<void>
  <A>(self: TxChunk<A>, other: TxChunk<A>): Effect.Effect<void>
} = dual(
  2,
  <A>(self: TxChunk<A>, other: TxChunk<A>): Effect.Effect<void> =>
    Effect.gen(function*() {
      const otherChunk = yield* get(other)
      yield* appendAll(self, otherChunk)
    }).pipe(Effect.tx)
)