Hyperlinkv0.8.0-beta.28

Array

Array.splitAtNonEmptyconsteffect/Array.ts:2705
(n: number): <A>(
  self: NonEmptyReadonlyArray<A>
) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]
<A>(self: NonEmptyReadonlyArray<A>, n: number): [
  beforeIndex: NonEmptyArray<A>,
  fromIndex: Array<A>
]

Splits a non-empty array into two parts at the given index. The first part is guaranteed to be non-empty (n is clamped to >= 1).

When to use

Use when downstream code requires the left side of the split to contain at least one element.

Example (Splitting a non-empty array)

import { Array } from "effect"

console.log(Array.splitAtNonEmpty(["a", "b", "c", "d", "e"], 3))
// [["a", "b", "c"], ["d", "e"]]
splittingsplitAt
Source effect/Array.ts:27059 lines
export const splitAtNonEmpty: {
  (n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]
  <A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {
  const _n = Math.max(1, Math.floor(n))
  return _n >= self.length ?
    [copy(self), []] :
    [prepend(self.slice(1, _n), headNonEmpty(self)), self.slice(_n)]
})
Referenced by 3 symbols