Hyperlinkv0.8.0-beta.28

TxChunk

TxChunk.takeconsteffect/TxChunk.ts:553
(n: number): <A>(self: TxChunk<A>) => Effect.Effect<void>
<A>(self: TxChunk<A>, n: number): Effect.Effect<void>

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]
})
combinators
Source effect/TxChunk.ts:5537 lines
export const take: {
  (n: number): <A>(self: TxChunk<A>) => Effect.Effect<void>
  <A>(self: TxChunk<A>, n: number): Effect.Effect<void>
} = dual(
  2,
  <A>(self: TxChunk<A>, n: number): Effect.Effect<void> => update(self, (current) => Chunk.take(current, n))
)