-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Please explain the feature or improvement you would like:
I would love to see the addition of mapValues
to the collection. This method would asynchronously transform the values of an object by applying the iteratee to each.
Please describe the use case where you would need that feature (the general situation or type of program where that would be helpful):
I often use records to organize my data, such as a record of user IDs paired with an access token:
const accessTokensByUserId: Record<Uuid, string> = {
[Uuid(...)]: "token1",
[Uuid(...)]: "token2",
}
.mapValues
would be useful here if I'd like to make a request for each user using their relative access-key:
async function fetchBirthday(accessToken: string): Promise<Date> { ... }
const birthdayByUser: Record<Uuid, Date> = await async.mapValues(accessTokensByUserId, fetchBirthday)
This would be opposed to the manual implementation:
async function fetchBirthday(accessToken: string): Promise<Date> { ... }
const birthdaysByUser: Record<Uuid, Date> = Object.fromEntries(
await async.map(Object.entries(birthdaysByUser), async ([uuid, token]) => {
const birthday = await fetchBirthday(token)
return [uuid, token]
})
) as Record<Uuid, Date> // Needed since Object.fromEntries types its keys as `string` where before they were `Uuid`
If you know another library similar to this one that already propose that feature please provide a link:
Async's mapValues
theoephraim
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request