Constructs a new Option from a nullable type. If the value is null or undefined, returns None, otherwise returns the value wrapped in a Some.
Option
null
undefined
None
Some
import { none, some, fromNullable } from 'fp-ts/Option'assert.deepStrictEqual(fromNullable(undefined), none)assert.deepStrictEqual(fromNullable(null), none)assert.deepStrictEqual(fromNullable(1), some(1)) Copy
import { none, some, fromNullable } from 'fp-ts/Option'assert.deepStrictEqual(fromNullable(undefined), none)assert.deepStrictEqual(fromNullable(null), none)assert.deepStrictEqual(fromNullable(1), some(1))
2.0.0
Constructs a new
Option
from a nullable type. If the value isnull
orundefined
, returnsNone
, otherwise returns the value wrapped in aSome
.