effect-io-ai

Package: effect
Module: Option

Option.fromIterable

Wraps the first element of an Iterable in a Some, or returns None if the iterable is empty.

When to use

Use when you need to safely extract the head of a collection, including generators or lazy iterables.

Details

Example (Getting the first element)

import { Option } from "effect"

console.log(Option.fromIterable([1, 2, 3]))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }

console.log(Option.fromIterable([]))
// Output: { _id: 'Option', _tag: 'None' }

See

Signature

declare const fromIterable: <A>(collection: Iterable<A>) => Option<A>

Source

Since v2.0.0