Hyperlinkv0.8.0-beta.28

Option

Option.fromNullishOrconsteffect/Option.ts:821
<A>(a: A): Option<NonNullable<A>>

Converts a nullable value (null or undefined) into an Option.

When to use

Use when you need JavaScript nullish values to become absence at an API boundary while all other values, including falsy ones, remain present.

Details

  • null or undefinedNone
  • Any other value → Some (typed as NonNullable<A>)

Example (Converting nullable values to an Option)

import { Option } from "effect"

console.log(Option.fromNullishOr(undefined))
// Output: { _id: 'Option', _tag: 'None' }

console.log(Option.fromNullishOr(null))
// Output: { _id: 'Option', _tag: 'None' }

console.log(Option.fromNullishOr(1))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
Source effect/Option.ts:8213 lines
export const fromNullishOr = <A>(
  a: A
): Option<NonNullable<A>> => (a == null ? none() : some(a as NonNullable<A>))
Referenced by 4 symbols