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://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/either.ts";

Convert a nullable value to an Either. If the value is null or undefined, it becomes a Left with the result of calling the error function. Otherwise, it becomes a Right with the non-null value.

@example
import * as E from "./either.ts";

const parseNumber = E.fromNullable(() => "Value is null or undefined");

const result1 = parseNumber(42); // Right(42)
const result2 = parseNumber(null); // Left("Value is null or undefined")
const result3 = parseNumber(undefined); // Left("Value is null or undefined")
function fromNullable<E>(fe: () => E): <A>(value: A) => Either<E, NonNullable<A>>;
§
fromNullable<E>(fe: () => E): <A>(value: A) => Either<E, NonNullable<A>>
[src]

§Type Parameters

§Parameters

§
fe: () => E
[src]

§Return Type

§
<A>(value: A) => Either<E, NonNullable<A>>
[src]