Skip to main content
Module

x/careful/mod.ts>Either

Safe containerization of values for TypeScript
Latest
type alias Either
import { type Either } from "https://deno.land/x/careful@v0.1.0/mod.ts";

The Either class represents a value of one of two possible types (a disjoint union). An Either is either a Left or a Right.

Examples

const generate = (): Either<number, string> => Math.random() > 0.5 ? left(5) : right("Hello!");

const either = generate() .mL((v) => v * v) .mR((v) => v.split(""));

console.log(either); // -> Left(25) or Right(["H", "e", "l", "l", "o", "!"])

definition: Left<TL> | Right<TR>