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

x/molt/lib/std/collections.ts>mapN

Update dependencies the Deno way
Latest
function mapN
import { mapN } from "https://deno.land/x/molt@0.17.2/lib/std/collections.ts";

Returns a new array, containing all elements in the given array transformed using the given transformer, except the ones that were transformed to null or undefined.

Examples

Example 1

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

const people = [
  { middleName: null },
  { middleName: "William" },
  { middleName: undefined },
  { middleName: "Martha" },
];
const foundMiddleNames = mapNotNullish(people, (it) => it.middleName);

assertEquals(foundMiddleNames, ["William", "Martha"]);

Parameters

array: Iterable<T>
transformer: (el: T) => O

Returns

NonNullable<O>[]