effect-io-ai

Package: effect
Module: Option

Option.getLeft

Converts an Either into an Option by discarding the right value and extracting the left value.

Details

This function transforms an Either into an Option as follows:

This utility is useful when you only care about the error case (Left) of an Either and want to handle it as an Option. By discarding the right value, it simplifies error-focused workflows.

Example

import { Either, Option } from "effect"

console.log(Option.getLeft(Either.right("ok")))
// Output: { _id: 'Option', _tag: 'None' }

console.log(Option.getLeft(Either.left("err")))
// Output: { _id: 'Option', _tag: 'Some', value: 'err' }

See

Signature

declare const getLeft: <R, L>(self: Either<R, L>) => Option<L>

Source

Since v2.0.0