Skip to main content
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.
Latest
function fromNullable
import { fromNullable } from "https://deno.land/x/fun@v2.0.0/option.ts";

The fromNullable function 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

Example 1

import * as O from "./option.ts";

const a: number | undefined = undefined;
const b: number | undefined = 2;
const c = [1, 2, 3];

const result1 = O.fromNullable(a); // None
const result2 = O.fromNullable(b); // Some<number>
const result3 = O.fromNullable(c[3]); // None

Returns

Option<NonNullable<A>>