Skip to main content
Module

x/hkts/option.ts>fromNullable

Functional programming tools: option, either, task, state, optics, etc.
Latest
variable fromNullable
import { fromNullable } from "https://deno.land/x/hkts@v0.0.52/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

type

<A>(a: A) => Option<NonNullable<A>>