Skip to main content
Module

x/careful/mod.ts>Option

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

Option is a type that represents either a value or no value. It is similar to the Maybe type in Haskell.

Examples

const generate = (): Option => Math.random() > 0.5 ? some(Math.random() * 10) : none();

const option: Option<string[]> = generate() .m((v) => v / 10) .m((v) => Mul x${v}) .m((v) => v.split(""));

console.log(option); // -> Some(["M", "u", "l", " ", "x", "0", ".", "1"]) or None

Type Parameters

T
  • Type of possible stored value
definition: Some<T> | None