Hyperlinkv0.8.0-beta.28

Array

Array.tailfunctioneffect/Array.ts:1187
<A>(self: Iterable<A>): Option.Option<Array<A>>

Returns all elements except the first safely, wrapped in an Option.

When to use

Use to safely get all elements after the first when the iterable may be empty.

Details

Allocates a new array via slice(1). Empty inputs return Option.none().

Example (Getting the tail)

import { Array } from "effect"

console.log(Array.tail([1, 2, 3, 4])) // Option.some([2, 3, 4])
console.log(Array.tail([])) // Option.none()
Source effect/Array.ts:11874 lines
export function tail<A>(self: Iterable<A>): Option.Option<Array<A>> {
  const as = fromIterable(self)
  return isReadonlyArrayNonEmpty(as) ? Option.some(tailNonEmpty(as)) : Option.none()
}