Hyperlinkv0.8.0-beta.28

TxChunk

TxChunk.sliceconsteffect/TxChunk.ts:623
(start: number, end: number): <A>(self: TxChunk<A>) => Effect.Effect<void>
<A>(self: TxChunk<A>, start: number, end: number): Effect.Effect<void>

Takes a slice of the TxChunk from start to end (exclusive).

Details

This function mutates the original TxChunk by keeping only the elements in the specified range. It does not return a new TxChunk reference.

Example (Taking a slice)

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

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

  // Take elements from index 2 to 5 (exclusive) - automatically transactional
  yield* TxChunk.slice(txChunk, 2, 5)

  const result = yield* TxChunk.get(txChunk)
  console.log(Chunk.toReadonlyArray(result)) // [3, 4, 5]
})
combinators
Source effect/TxChunk.ts:6238 lines
export const slice: {
  (start: number, end: number): <A>(self: TxChunk<A>) => Effect.Effect<void>
  <A>(self: TxChunk<A>, start: number, end: number): Effect.Effect<void>
} = dual(
  3,
  <A>(self: TxChunk<A>, start: number, end: number): Effect.Effect<void> =>
    update(self, (current) => Chunk.take(Chunk.drop(current, start), end - start))
)