<A>(self: Chunk<A>): AReturns 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()))) // trueunsafe
Source effect/Chunk.ts:15101 lines
export const const lastUnsafe: <A>(self: Chunk<A>) => AReturns 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
lastUnsafe = <function (type parameter) A in <A>(self: Chunk<A>): AA>(self: Chunk<A>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) A in <A>(self: Chunk<A>): AA>): function (type parameter) A in <A>(self: Chunk<A>): AA => const getUnsafe: {
(index: number): <A>(self: Chunk<A>) => A
<A>(self: Chunk<A>, index: number): A
}
getUnsafe(self: Chunk<A>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self, self: Chunk<A>(parameter) self: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Chunk<out A>.length: numberlength - 1)Referenced by 2 symbols