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
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
Parameters
a: A