Skip to main content
Module

x/functional/mod.js>Maybe

Common Functional Programming Algebraic data types for JavaScript that is compatible with most modern browsers and Deno.
Latest
variable Maybe
import { Maybe } from "https://deno.land/x/functional@v1.3.4/mod.js";

Maybe

The Maybe is the most common sum type; it represents the possibility of a value being null or undefined.

The Maybe type implements the following algebras:

  • [x] Alternative
  • [x] Comonad
  • [x] Monad

Example

import Maybe from "https://deno.land/x/functional@v1.3.2/library/Maybe.js";

const containerA = Maybe.Just(42).map(x => x + 2);
const containerB = Maybe.Nothing.map(x => x + 2);

assert(Maybe.Just.is(containerA));
assert(containerA.extract() === 44);
assert(Maybe.Nothing.is(containerB));