Hyperlinkv0.8.0-beta.28

Array

Array.unappendconsteffect/Array.ts:1058
<A>(self: NonEmptyReadonlyArray<A>): [
  arrayWithoutLastElement: Array<A>,
  lastElement: A
]

Splits a non-empty array into all elements except the last, and the last element.

When to use

Use when you need to split a non-empty array into the elements before the last element and the last element.

Details

Returns a tuple [init, last] and requires a NonEmptyReadonlyArray.

Example (Destructuring init and last)

import { Array } from "effect"

const result = Array.unappend([1, 2, 3, 4])
console.log(result) // [[1, 2, 3], 4]
Source effect/Array.ts:10583 lines
export const unappend = <A>(
  self: NonEmptyReadonlyArray<A>
): [arrayWithoutLastElement: Array<A>, lastElement: A] => [initNonEmpty(self), lastNonEmpty(self)]