| 14 | // Lifted from https://github.com/sindresorhus/p-reduce |
| 15 | // Thanks @sindresorhus! 🙏 |
| 16 | const pReduce = (iterable, reducer, initVal) => |
| 17 | new Promise((resolve, reject) => { |
| 18 | const iterator = iterable[Symbol.iterator]() |
| 19 | let i = 0 |
| 20 | |
| 21 | const next = total => { |
| 22 | const el = iterator.next() |
| 23 | |
| 24 | if (el.done) { |
| 25 | resolve(total) |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | Promise.all([total, el.value]) |
| 30 | .then(value => { |
| 31 | // eslint-disable-next-line no-plusplus |
| 32 | next(reducer(value[0], value[1], i++)) |
| 33 | }) |
| 34 | .catch(reject) |
| 35 | } |
| 36 | |
| 37 | next(initVal) |
| 38 | }) |
| 39 | |
| 40 | // Lifted from https://github.com/sindresorhus/p-map-series |
| 41 | // Thanks @sindresorhus! 🙏 |