Functional Promises

suggest change

Native Promise has no map, filter, or reduce. These examples use Bluebird, which adds them.

Example of map:

const Promise = require('bluebird');

Promise.resolve([ 1, 2, 3 ]).map(el => {
   return Promise.resolve(el * el) // return some async operation in real world
})

Example of filter:

const Promise = require('bluebird');

Promise.resolve([ 1, 2, 3 ]).filter(el => {
  return Promise.resolve(el % 2 === 0) // return some async operation in real world
}).then(console.log)

Example of reduce:

const Promise = require('bluebird');

Promise.resolve([ 1, 2, 3 ]).reduce((prev, curr) => {
  return Promise.resolve(prev + curr) // return some async operation in real world
}).then(console.log)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents