import { mapOrElse } from "https://deno.land/x/optio@1.0.0/operators/transform.ts";
Computes a default function result (if None
), or applies a different function to the contained value (if Some
).
Examples
Example 1
Example 1
import { mapOrElse, Option, Some } from "https://deno.land/x/optio/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
const option: Option<string> = Some("Hello");
assertEquals(mapOrElse(option, () => 2 ** 3, ({ length }) => length), 5);