Hyperlinkv0.8.0-beta.28

Array

Array.lastconsteffect/Array.ts:1134
<A>(self: ReadonlyArray<A>): Option.Option<A>

Returns the last element of an array safely wrapped in Option.some, or Option.none if the array is empty.

When to use

Use to safely get the last element of an array that may be empty.

Example (Getting the last element)

import { Array } from "effect"

console.log(Array.last([1, 2, 3])) // Some(3)
console.log(Array.last([])) // None
Source effect/Array.ts:11342 lines
export const last = <A>(self: ReadonlyArray<A>): Option.Option<A> =>
  isReadonlyArrayNonEmpty(self) ? Option.some(lastNonEmpty(self)) : Option.none()