Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fathym_common/deps.ts>mapValues

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Go to Latest
function mapValues
Re-export
import { mapValues } from "https://deno.land/x/fathym_common@v0.0.184/deps.ts";

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.

Examples

Example 1

import { mapValues } from "https://deno.land/std@0.224.0/collections/map_values.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

const usersById = {
  "a5ec": { name: "Mischa" },
  "de4f": { name: "Kim" },
};
const namesById = mapValues(usersById, (it) => it.name);

assertEquals(
  namesById,
  {
    "a5ec": "Mischa",
    "de4f": "Kim",
  },
);

Type Parameters

T
O
K extends string

Parameters

record: Readonly<Record<K, T>>
transformer: (value: T, key: K) => O

Returns

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.

Examples

Example 1

import { mapValues } from "https://deno.land/std@0.224.0/collections/map_values.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

const usersById = {
  "a5ec": { name: "Mischa" },
  "de4f": { name: "Kim" },
};
const namesById = mapValues(usersById, (it) => it.name);

assertEquals(
  namesById,
  {
    "a5ec": "Mischa",
    "de4f": "Kim",
  },
);

Type Parameters

T
O
K extends string

Parameters

record: Readonly<Partial<Record<K, T>>>
transformer: (value: T, key: K) => O

Returns

Partial<Record<K, O>>