<A>(self: Iterable<A>): AGets the first element of an Iterable without returning an Option.
When to use
Use when the Iterable is known to be non-empty and direct access to the
first element is preferred over handling Option.none.
Gotchas
Throws if the Iterable is empty.
Example (Getting the first element unsafely)
import { Iterable } from "effect"
const numbers = [1, 2, 3]
console.log(Iterable.headUnsafe(numbers)) // 1
const letters = "hello"
console.log(Iterable.headUnsafe(letters)) // "h"
// Iterable.headUnsafe(Iterable.empty<number>())
// throws Error: "headUnsafe: empty iterable"
// Use only when you're certain the iterable is non-empty
const nonEmpty = Iterable.range(1, 10)
console.log(Iterable.headUnsafe(nonEmpty)) // 1getters
Source effect/Iterable.ts:5466 lines
export const const headUnsafe: <A>(
self: Iterable<A>
) => A
Gets the first element of an Iterable without returning an Option.
When to use
Use when the Iterable is known to be non-empty and direct access to the
first element is preferred over handling Option.none.
Gotchas
Throws if the Iterable is empty.
Example (Getting the first element unsafely)
import { Iterable } from "effect"
const numbers = [1, 2, 3]
console.log(Iterable.headUnsafe(numbers)) // 1
const letters = "hello"
console.log(Iterable.headUnsafe(letters)) // "h"
// Iterable.headUnsafe(Iterable.empty<number>())
// throws Error: "headUnsafe: empty iterable"
// Use only when you're certain the iterable is non-empty
const nonEmpty = Iterable.range(1, 10)
console.log(Iterable.headUnsafe(nonEmpty)) // 1
headUnsafe = <function (type parameter) A in <A>(self: Iterable<A>): AA>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): AA>): function (type parameter) A in <A>(self: Iterable<A>): AA => {
const const iterator: Iterator<A, any, any>iterator = self: Iterable<A>self[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]()
const const result: IteratorResult<A, any>result = const iterator: Iterator<A, any, any>iterator.Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next()
if (const result: IteratorResult<A, any>result.done?: boolean | undefineddone) throw new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error("headUnsafe: empty iterable")
return const result: IteratorYieldResult<A>result.IteratorYieldResult<A>.value: Avalue
}Referenced by 3 symbols