Skip to main content

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Downloads1/wk
Published2 years ago (0.215.0)
function mapNotNullish
mapNotNullish<T, O>(
array: Iterable<T>,
transformer: (el: T) => O
): NonNullable<O>[]

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 "@std/collections/map_not_nullish";
import { assertEquals } from "@std/assert/assert_equals";

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

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

Type Parameters

Parameters

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

Return Type

NonNullable<O>[]

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/collections

Import symbol

import { mapNotNullish } from "@std/collections/map_not_nullish";
or

Import directly with a jsr specifier

import { mapNotNullish } from "jsr:@std/collections/map_not_nullish";