0.0.2 • Published 5 months ago

@duorun/maybe v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@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
  }
}
0.0.2

5 months ago

0.0.1

5 months ago