Skip to main content
Module

x/optio/mod.ts>mapOr

Minimum option type port of Rust
Latest
function mapOr
import { mapOr } from "https://deno.land/x/optio@1.0.0/mod.ts";

Returns the provided default value (if None), or applies a function to the contained value (if Some).

Examples

Example 1

import { mapOr, 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(mapOr(option, 0, ({ length }) => length), 5);

Parameters

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