Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xnimorz/maybe

Maybe monad with full types support!
https://github.com/xnimorz/maybe

Last synced: about 1 month ago
JSON representation

Maybe monad with full types support!

Awesome Lists containing this project

README

        

# @duorun/Maybe

TypeScript implementation maybe monad.

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

## Install:

```shell
npm i @duorun/maybe --save
```

## Playground:

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

## Usages

Value is defined:

```js
just("bar"); // Maybe
```

Value is empty:

```js
none(); // Maybe
```

Note: null / undefeind can be valid data:

```js
just(null); // Maybe
```

Check if value is defined:

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

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