xnimorz / maybe

Maybe monad with full types support!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@duorun/Maybe

TypeScript implementation maybe monad.

  1. Easy-to-use
  2. Small (267 Bytes)!
  3. Typed API

Install:

npm i @duorun/maybe --save

Playground:

Sandbox: https://codesandbox.io/p/sandbox/nifty-lake-5wpq2y

Usages

Value is defined:

just("bar"); // Maybe<string>

Value is empty:

none(); // Maybe<never>

Note: null / undefeind can be valid data:

just(null); // Maybe<null>

Check if value is defined:

import { isNone } from "@duorun/maybe";

function test(maybe: Maybe<string>) {
  if (isNone(maybe)) {
    // maybe is None
  } else {
    // maybe is just
    maybe.value; // string
  }
}

About

Maybe monad with full types support!

License:MIT License


Languages

Language:TypeScript 100.0%