effect-io-ai

Package: effect
Module: Chunk

Chunk.lastUnsafe

Returns the last element of this chunk.

When to use

Use when you know the chunk is non-empty and need the last element directly without handling Option.none.

Gotchas

Throws an error if the chunk is empty.

Example (Getting the last element unsafely)

import { Chunk, Option } from "effect"

const chunk = Chunk.make(1, 2, 3, 4)
console.log(Chunk.lastUnsafe(chunk)) // 4

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

// Use Chunk.last when the chunk may be empty
console.log(Option.isNone(Chunk.last(Chunk.empty()))) // true

Signature

declare const lastUnsafe: <A>(self: Chunk<A>) => A

Source

Since v4.0.0