Function: fromNullable()
fromNullable<
T>(value):Option<T>
Defined in: option/constructors/index.ts:55
Converts a nullable value to an Option.
If the value is not null or undefined, returns Some with the value. Otherwise, returns None.
Type Parameters
T
T
Parameters
value
The nullable value
T | null | undefined
Returns
Option<T>
Option containing the value or None
Example
fromNullable(42) // => Some(42)
fromNullable(null) // => None
fromNullable(undefined) // => None
// With array find
const user = fromNullable(users.find(u => u.id === id))