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

https://github.com/wdalmut/maybe-with-promises-2

Improved example of usage for maybes with promises
https://github.com/wdalmut/maybe-with-promises-2

example javascript js maybe-monad promise

Last synced: 3 days ago
JSON representation

Improved example of usage for maybes with promises

Awesome Lists containing this project

README

          

# Use maybes with promises

In order to improve readability an example of data maybe with promises

```
const is_confirmed = compose(equals(true), prop('confirmed'));
get_order(id)
.then(ifElse(is_confirmed, Just, Nothing))
.then(map(create_guests_for_event))
.then(map(send_invoice_ticket))
.then(console.log)
;
```

If the order from `get_order` is not confirmed `confirmed = false` nothing is
executed.

## Usage

### Install dependencies

```sh
npm install
```

### Run it

Execute the data pipeline

```sh
$ node index.js 1
Guests created! { id: '1', confirmed: true, price: 89.9 }
Invoice sent! Promise { { id: '1', confirmed: true, price: 89.9 } }
Maybe {
value: Promise { { id: '1', confirmed: true, price: 89.9 } } }
```

_nothing to do (confirmed = false)_

```sh
node index.js 0
Maybe {}
```