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
- Host: GitHub
- URL: https://github.com/wdalmut/maybe-with-promises-2
- Owner: wdalmut
- Created: 2018-09-01T06:36:30.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-01T06:36:43.000Z (almost 8 years ago)
- Last Synced: 2025-07-27T13:31:17.380Z (11 months ago)
- Topics: example, javascript, js, maybe-monad, promise
- Language: JavaScript
- Homepage: https://github.com/wdalmut/maybe-with-promises
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 {}
```