effect-io-ai

Package: effect
Module: Chunk

Chunk.lastNonEmpty

Returns the last element of this non empty chunk.

Example (Getting the last element of a non-empty chunk)

import { Chunk } from "effect"

const nonEmptyChunk = Chunk.make(1, 2, 3, 4)
console.log(Chunk.lastNonEmpty(nonEmptyChunk)) // 4

const singleElement = Chunk.make("hello")
console.log(Chunk.lastNonEmpty(singleElement)) // "hello"

// Type safety: this function only accepts NonEmptyChunk
// Chunk.lastNonEmpty(Chunk.empty()) // TypeScript error

Signature

declare const lastNonEmpty: <A>(self: NonEmptyChunk<A>) => A

Source

Since v3.4.0