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
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
TOParameters
Return Type
NonNullable<O>[]