Hyperlinkv0.8.0-beta.28

Chunk

Chunk.splitAtconsteffect/Chunk.ts:1956
(n: number): <A>(
  self: Chunk<A>
) => [beforeIndex: Chunk<A>, fromIndex: Chunk<A>]
<A>(self: Chunk<A>, n: number): [
  beforeIndex: Chunk<A>,
  fromIndex: Chunk<A>
]

Returns two splits of this chunk at the specified index.

Example (Splitting at an index)

import { Chunk } from "effect"

const chunk = Chunk.make(1, 2, 3, 4, 5, 6)
const [before, after] = Chunk.splitAt(chunk, 3)
console.log(Chunk.toArray(before)) // [1, 2, 3]
console.log(Chunk.toArray(after)) // [4, 5, 6]

// Split at index 0
const [empty, all] = Chunk.splitAt(chunk, 0)
console.log(Chunk.toArray(empty)) // []
console.log(Chunk.toArray(all)) // [1, 2, 3, 4, 5, 6]

// Split beyond length
const [allElements, empty2] = Chunk.splitAt(chunk, 10)
console.log(Chunk.toArray(allElements)) // [1, 2, 3, 4, 5, 6]
console.log(Chunk.toArray(empty2)) // []
splitting
Source effect/Chunk.ts:19564 lines
export const splitAt: {
  (n: number): <A>(self: Chunk<A>) => [beforeIndex: Chunk<A>, fromIndex: Chunk<A>]
  <A>(self: Chunk<A>, n: number): [beforeIndex: Chunk<A>, fromIndex: Chunk<A>]
} = dual(2, <A>(self: Chunk<A>, n: number): [Chunk<A>, Chunk<A>] => [take(self, n), drop(self, n)])
Referenced by 1 symbols