Hyperlinkv0.8.0-beta.28

Chunk

Chunk.lastUnsafeconsteffect/Chunk.ts:1510
<A>(self: Chunk<A>): A

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
unsafe
Source effect/Chunk.ts:15101 lines
export const lastUnsafe = <A>(self: Chunk<A>): A => getUnsafe(self, self.length - 1)
Referenced by 2 symbols