Function mapValues
- map
Values <T, O, K>(record, transformer): Record<K, O> Type Parameters
Parameters
Returns Record<K, O>
A new record with all values transformed by the given transformer.
Example: Basic usage
import { mapValues } from "@std/collections/map-values";
import { assertEquals } from "@std/assert";
const usersById = {
a5ec: { name: "Mischa" },
de4f: { name: "Kim" },
};
const namesById = mapValues(usersById, (user) => user.name);
assertEquals(
namesById,
{
a5ec: "Mischa",
de4f: "Kim",
},
);- map
Values <T, O, K>(record, transformer): Partial<Record<K, O>> Applies the given transformer to all values in the given record and returns a new record containing the resulting keys associated to the last value that produced them.
Type Parameters
Parameters
Returns Partial<Record<K, O>>
A new record with all values transformed by the given transformer.
Example: Basic usage
import { mapValues } from "@std/collections/map-values";
import { assertEquals } from "@std/assert";
const usersById = {
"a5ec": { name: "Mischa" },
"de4f": { name: "Kim" },
};
const namesById = mapValues(usersById, (user) => user.name);
assertEquals(
namesById,
{
"a5ec": "Mischa",
"de4f": "Kim",
},
);
Applies the given transformer to all values in the given record and returns a new record containing the resulting keys associated to the last value that produced them.