Hyperlinkv0.8.0-beta.28

TxChunk

TxChunk.mapconsteffect/TxChunk.ts:660
<A>(f: (a: NoInfer<A>) => A): (self: TxChunk<A>) => Effect.Effect<void>
<A>(self: TxChunk<A>, f: (a: A) => A): Effect.Effect<void>

Maps each element of the TxChunk using a function that returns the same element type.

Details

This function mutates the original TxChunk by transforming each element in place. It does not return a new TxChunk reference.

Example (Mapping elements)

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

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

  // Transform each element atomically (must maintain same type)
  yield* TxChunk.map(txChunk, (n) => n * 2)

  const result = yield* TxChunk.get(txChunk)
  console.log(Chunk.toReadonlyArray(result)) // [2, 4, 6, 8]
})
combinators
Source effect/TxChunk.ts:6607 lines
export const map: {
  <A>(f: (a: NoInfer<A>) => A): (self: TxChunk<A>) => Effect.Effect<void>
  <A>(self: TxChunk<A>, f: (a: A) => A): Effect.Effect<void>
} = dual(
  2,
  <A>(self: TxChunk<A>, f: (a: A) => A): Effect.Effect<void> => update(self, (current) => Chunk.map(current, f))
)