@duorun/maybe
v0.0.2
Published
Simple and typed Maybe monad
Downloads
3
Readme
@duorun/Maybe
TypeScript implementation maybe monad.
- Easy-to-use
- Small (267 Bytes)!
- 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
}
}