Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/fun/option.ts>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 fromNullable
import { fromNullable } from "https://deno.land/x/fun@v2.0.0-alpha.6/option.ts";

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>>