Hyperlinkv0.8.0-beta.28

Array

Array.unprependconsteffect/Array.ts:1025
<A>(self: NonEmptyReadonlyArray<A>): [
  firstElement: A,
  remainingElements: Array<A>
]

Splits a non-empty array into its first element and the remaining elements.

When to use

Use when you have a NonEmptyReadonlyArray and need both its first element and the remaining elements as separate values.

Details

Returns a tuple [head, tail] and requires a NonEmptyReadonlyArray.

Example (Destructuring head and tail)

import { Array } from "effect"

const result = Array.unprepend([1, 2, 3, 4])
console.log(result) // [1, [2, 3, 4]]
Source effect/Array.ts:10253 lines
export const unprepend = <A>(
  self: NonEmptyReadonlyArray<A>
): [firstElement: A, remainingElements: Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]