Skip to content

wdalmut/maybe-with-promises-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

npm install

Run it

Execute the data pipeline

$ 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)

node index.js 0
Maybe {}

Releases

No releases published

Packages

No packages published