Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

fromNullable

import { fromNullable } from "https://raw.githubusercontent.com/baetheus/fun/main/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>.

@example
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
function fromNullable<A>(a: A): Option<NonNullable<A>>;
§
fromNullable<A>(a: A): Option<NonNullable<A>>
[src]

§Type Parameters

§Parameters

§Return Type

§
Option<NonNullable<A>>
[src]