Skip to main content
Module

x/fun/mod.ts>option.fromNullable

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function option.fromNullable
import { option } from "https://deno.land/x/fun@v2.0.0-alpha.6/mod.ts";
const { fromNullable } = option;

fromNullable takes a potentially null or undefined value and maps null or undefined to None and non-null and non-undefined values to Some<NonNullable>

Examples

const a: number | undefined = undefined; const b: number | undefined = 2; const optionNumber = fromNullable(a); // None const optionNumber = fromNullable(b); // Some const numberArray = [1, 2, 3]; const optionFourthEntry = fromNullable(numberArray[3]); // None

Returns

Option<NonNullable<A>>