Skip to content

Instantly share code, notes, and snippets.

@dignifiedquire
Created January 7, 2017 16:48
Show Gist options
  • Save dignifiedquire/dd08d2f3806a7b87f45b00c41fe109b7 to your computer and use it in GitHub Desktop.
Save dignifiedquire/dd08d2f3806a7b87f45b00c41fe109b7 to your computer and use it in GitHub Desktop.
'use strict'
const expect = require('chai').expect
function mapSeries (list, func) {
const res = []
return list.reduce((acc, next) => {
return acc.then((val) => {
res.push(val)
return func(next)
})
}, Promise.resolve(null)).then((val) => {
res.push(val)
return res.slice(1)
})
}
describe.only('map', () => {
it('maps', () => {
const hashes = [
'hash1',
'hash2',
'hash3'
]
const get = (hash) => Promise.resolve(hash + 'cool')
return mapSeries(hashes, get).then((res) => {
expect(res).to.be.eql([
'hash1cool',
'hash2cool',
'hash3cool'
])
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment