sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.31k stars 173 forks source link

Include the index number for an array item in the async callback function parameter in `reduce` #290

Closed UnKnoWn-Consortium closed 1 year ago

UnKnoWn-Consortium commented 1 year ago

Similar to #288 and more so to the vanila Array.prototype.reduce, the index number for an array item is added as one of the async callback function parameters.

E.g.:

const users = await reduce(userIds, async (acc, userId, index) => {
  const user = await api.users.find(userId)
  return {
    ...acc,
    [userId]: user
  }
}, {})