effect-io-ai

Package: effect
Module: TxChunk

TxChunk.take

Takes the first n elements from the TxChunk.

Details

This function mutates the original TxChunk by keeping only the first n elements. It does not return a new TxChunk reference.

Example (Taking leading elements)

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

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

  // Take only the first 3 elements - automatically transactional
  yield* TxChunk.take(txChunk, 3)

  const result = yield* TxChunk.get(txChunk)
  console.log(Chunk.toReadonlyArray(result)) // [1, 2, 3]
})

Signature

declare const take: { (n: number): <A>(self: TxChunk<A>) => Effect.Effect<void>; <A>(self: TxChunk<A>, n: number): Effect.Effect<void>; }

Source

Since v4.0.0