Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

mapNullable

import { mapNullable } from "https://raw.githubusercontent.com/baetheus/fun/main/option.ts";

Apply a mapping function to an Option but if the mapping function returns null or undefined the null or undefined value is lifted into None.

@example
import * as O from "./option.ts";
import { pipe } from "./fn.ts";

const result1 = pipe(
  O.some([1, 2, 3]),
  O.mapNullable(arr => arr[10]),
); // None
const result2 = pipe(
  O.constNone<Array<number>>(),
  O.mapNullable(arr => arr[0]),
); // None
const result3 = pipe(
  O.some([1, 2, 3]),
  O.mapNullable(arr => arr[0]),
); // Some(1)
function mapNullable<A, I>(f: (a: A) => I | null | undefined): (ua: Option<A>) => Option<I>;
§
mapNullable<A, I>(f: (a: A) => I | null | undefined): (ua: Option<A>) => Option<I>
[src]

§Type Parameters

§Parameters

§
f: (a: A) => I | null | undefined
[src]

§Return Type

§
(ua: Option<A>) => Option<I>
[src]