Skip to main content
Module

x/nameable/deps.ts>map

Cross-check whether it can be used as a package name or domain name
Latest
variable map
import { map } from "https://deno.land/x/nameable@v1.1.0-beta.4/deps.ts";

Takes a function, applies the function to each, and returns a result of the same shape.

Examples

Example 1

const triple = (val: number):number => val * 3
map(triple, [1, 2, 3]) // [3, 6, 9]
map(triple, { tom: 1, john: 2, bob: 3 }) // { tom: 3, john: 6, bob: 9}

type

{ <T extends readonly unknown[], U>(fn: (
value: T[number],
index: number,
list: T,
) => U
, list: T
): MapArray<U, T>; <T extends { [k: string]: unknown; }, U>(fn: (
val: T[keyof T],
prop: keyof T,
list: T,
) => U
, list: T
): MapObject<U, T>; }