With async/await this can become:<p><pre><code> const reduceP = async (fn, identity, listP) => {
const values = await Promise.all(listP)
return values.reduce(fn, identity)
}
</code></pre>
The whole thing feels like a synthetic and overcomplicated example, though. In practice I'm sure I'd just write:<p><pre><code> let total = 0
while (listP.length > 0) {
total += await listP.pop()
}</code></pre>