Hyperlinkv0.8.0-beta.28

Option

Option.fromNullOrconsteffect/Option.ts:899
<A>(a: A): Option<Exclude<A, null>>

Converts a possibly null value into an Option, leaving undefined as a valid Some.

When to use

Use when you want to treat only null as absent while preserving undefined as a meaningful value.

Details

  • nullNone
  • Any other value (including undefined) → Some

Example (Converting possibly null values to an Option)

import { Option } from "effect"

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

console.log(Option.fromNullOr(undefined))
// Output: { _id: 'Option', _tag: 'Some', value: undefined }

console.log(Option.fromNullOr(42))
// Output: { _id: 'Option', _tag: 'Some', value: 42 }
Source effect/Option.ts:8993 lines
export const fromNullOr = <A>(
  a: A
): Option<Exclude<A, null>> => (a === null ? none() : some(a as Exclude<A, null>))
Referenced by 2 symbols