@duorun/maybe
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @duorun/maybe

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

20.9 kB

Total Files

12

Last publish

Collaborators

  • xnimorz