Hyperlinkv0.8.0-beta.28

Chunk

Chunk.headUnsafeconsteffect/Chunk.ts:1438
<A>(self: Chunk<A>): A

Returns the first element of this chunk.

When to use

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

Gotchas

Throws an error if the chunk is empty.

Example (Getting the first element unsafely)

import { Chunk, Option } from "effect"

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

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

// Use Chunk.head when the chunk may be empty
console.log(Option.isNone(Chunk.head(Chunk.empty()))) // true
unsafe
Source effect/Chunk.ts:14381 lines
export const headUnsafe = <A>(self: Chunk<A>): A => getUnsafe(self, 0)
Referenced by 2 symbols