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

x/fathym_common/src/src.deps.ts>firstNotNullishOf

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

Applies the given selector to elements in the given array until a value is produced that is neither null nor undefined and returns that value. Returns undefined if no such value is produced.

Examples

Example 1

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

const tables = [
  { number: 11, order: null },
  { number: 12, order: "Soup" },
  { number: 13, order: "Salad" },
];
const nextOrder = firstNotNullishOf(tables, (it) => it.order);

assertEquals(nextOrder, "Soup");

Parameters

array: Iterable<T>
selector: (item: T) => O | undefined | null

Returns

NonNullable<O> | undefined