effect-io-ai

Package: effect
Module: Effect

Effect.fromNullishOr

Converts a nullable value to an Effect, failing with a NoSuchElementError when the value is null or undefined.

Example (Failing on nullish values)

import { Console, Effect } from "effect"

const program = Effect.fn(function*(input: string | null) {
  const value = yield* Effect.fromNullishOr(input)
  yield* Console.log(value)
},
  Effect.catch(() => Console.log("missing"))
)

Effect.runPromise(program(null))
// Output: missing
Effect.runPromise(program("hello"))
// Output: hello

Signature

declare const fromNullishOr: <A>(value: A) => Effect<NonNullable<A>, Cause.NoSuchElementError>

Source

Since v4.0.0