Hyperlinkv0.8.0-beta.28

TxChunk

TxChunk.modifyconsteffect/TxChunk.ts:258
<A, R>(
  f: (
    current: Chunk.Chunk<NoInfer<A>>
  ) => [returnValue: R, newValue: Chunk.Chunk<A>]
): (self: TxChunk<A>) => Effect.Effect<R>
<A, R>(
  self: TxChunk<A>,
  f: (
    current: Chunk.Chunk<A>
  ) => [returnValue: R, newValue: Chunk.Chunk<A>]
): Effect.Effect<R>

Modifies the value of the TxChunk using the provided function.

Details

This function mutates the original TxChunk by updating its internal state. It does not return a new TxChunk reference.

Example (Modifying while returning a value)

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

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

  // Modify and return both old size and new chunk
  const oldSize = yield* TxChunk.modify(txChunk, (chunk) => [
    Chunk.size(chunk), // return value (old size)
    Chunk.append(chunk, 4) // new value
  ])

  console.log(oldSize) // 3

  const newChunk = yield* TxChunk.get(txChunk)
  console.log(Chunk.toReadonlyArray(newChunk)) // [1, 2, 3, 4]
})
combinators
Source effect/TxChunk.ts:25815 lines
export const modify: {
  <A, R>(
    f: (current: Chunk.Chunk<NoInfer<A>>) => [returnValue: R, newValue: Chunk.Chunk<A>]
  ): (self: TxChunk<A>) => Effect.Effect<R>
  <A, R>(
    self: TxChunk<A>,
    f: (current: Chunk.Chunk<A>) => [returnValue: R, newValue: Chunk.Chunk<A>]
  ): Effect.Effect<R>
} = dual(
  2,
  <A, R>(
    self: TxChunk<A>,
    f: (current: Chunk.Chunk<A>) => [returnValue: R, newValue: Chunk.Chunk<A>]
  ): Effect.Effect<R> => TxRef.modify(self.ref, f)
)
Referenced by 3 symbols