Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/optio/operators/transform.ts>mapOrElse

Minimum option type port of Rust
Latest
function mapOrElse
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

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);

Parameters

option: Option<T>
defaultFn: () => U
fn: (value: T) => U