https://github.com/wdalmut/maybe-with-promises-3
Maybe with promises example using Ramda and Sanctuary (only maybes)
https://github.com/wdalmut/maybe-with-promises-3
example maybe ramda sanctuary
Last synced: 11 months ago
JSON representation
Maybe with promises example using Ramda and Sanctuary (only maybes)
- Host: GitHub
- URL: https://github.com/wdalmut/maybe-with-promises-3
- Owner: wdalmut
- Created: 2018-09-01T07:29:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-01T16:44:03.000Z (almost 8 years ago)
- Last Synced: 2025-06-04T12:16:26.147Z (about 1 year ago)
- Topics: example, maybe, ramda, sanctuary
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 1
- 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, always(Nothing)))
.then(map(create_guests_for_event))
.then(map(send_invoice_ticket))
.then(prop('value'))
.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 } }
{ id: '1', confirmed: true, price: 89.9 }
```
_nothing to do (confirmed = false)_
```sh
node index.js 0
undefined
```