Hyperlinkv0.8.0-beta.28

Chunk

Chunk.splitNonEmptyAtconsteffect/Chunk.ts:1993
(n: number): <A>(
  self: NonEmptyChunk<A>
) => [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>]
<A>(self: NonEmptyChunk<A>, n: number): [
  beforeIndex: NonEmptyChunk<A>,
  fromIndex: Chunk<A>
]

Splits a NonEmptyChunk at n, returning a non-empty prefix and the remaining suffix.

Details

n is floored and normalized to at least 1. If n is greater than or equal to the chunk length, the first result is the original chunk and the second result is empty.

Example (Splitting non-empty chunks at an index)

import { Chunk } from "effect"

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

// Split at 1 (minimum)
const [first, rest] = Chunk.splitNonEmptyAt(nonEmptyChunk, 1)
console.log(Chunk.toArray(first)) // [1]
console.log(Chunk.toArray(rest)) // [2, 3, 4, 5, 6]

// The first part is guaranteed to be NonEmptyChunk
// while the second part may be empty
splitting
Source effect/Chunk.ts:19939 lines
export const splitNonEmptyAt: {
  (n: number): <A>(self: NonEmptyChunk<A>) => [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>]
  <A>(self: NonEmptyChunk<A>, n: number): [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>]
} = dual(2, <A>(self: NonEmptyChunk<A>, n: number): [Chunk<A>, Chunk<A>] => {
  const _n = Math.max(1, Math.floor(n))
  return _n >= self.length ?
    [self, empty()] :
    [take(self, _n), drop(self, _n)]
})