Hyperlinkv0.8.0-beta.28

TxChunk

TxChunk.prependconsteffect/TxChunk.ts:436
<A>(element: A): (self: TxChunk<A>) => Effect.Effect<void>
<A>(self: TxChunk<A>, element: A): Effect.Effect<void>

Prepends an element to the beginning of the TxChunk.

Details

This function mutates the original TxChunk by adding the element to the beginning. It does not return a new TxChunk reference.

Example (Prepending an element)

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

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

  // Add element to the beginning atomically
  yield* TxChunk.prepend(txChunk, 1)

  const result = yield* TxChunk.get(txChunk)
  console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3, 4]
})
combinators
Source effect/TxChunk.ts:4367 lines
export const prepend: {
  <A>(element: A): (self: TxChunk<A>) => Effect.Effect<void>
  <A>(self: TxChunk<A>, element: A): Effect.Effect<void>
} = dual(
  2,
  <A>(self: TxChunk<A>, element: A): Effect.Effect<void> => update(self, (current) => Chunk.prepend(current, element))
)