import { mapNullable } from "https://deno.land/x/fun@v.2.0.0-alpha.11/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.
Examples
Example 1
Example 1
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)