effect-io-ai

Package: effect
Module: Effect

Effect.catchNoSuchElement

Catches NoSuchElementError failures and converts them to Option.none.

When to use

Use when you expect missing-value failures and want them to become an optional success while all other failures keep failing.

Details

Success values become Option.some, NoSuchElementError becomes Option.none, and all other errors are preserved.

Example (Recovering from missing Option values)

import { Effect, Option } from "effect"

const some = Effect.fromNullishOr(1).pipe(Effect.catchNoSuchElement)
const none = Effect.fromNullishOr(null).pipe(Effect.catchNoSuchElement)

Effect.runPromise(some).then(console.log) // { _id: 'Option', _tag: 'Some', value: 1 }
Effect.runPromise(none).then(console.log) // { _id: 'Option', _tag: 'None' }

See

Signature

declare const catchNoSuchElement: <A, E, R>(self: Effect<A, E, R>) => Effect<Option<A>, Exclude<E, Cause.NoSuchElementError>, R>

Source

Since v4.0.0