Skip to content

reduce

Reduce an array with an async function

230 bytes

Usage

A reduce that handles callback functions that return a promise.

import * as _ from 'radashi'
const userIds = [1, 2, 3, 4]
const users = await _.reduce(
userIds,
async (acc, userId) => {
const user = await api.users.find(userId)
return {
...acc,
[userId]: user,
}
},
{},
)