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

x/optio/operators/extract.ts>unwrapOrElse

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

Returns the contained Some value, otherwise computes it from a closure.

Examples

Example 1

import { None, Some } from "https://deno.land/x/optio/spec.ts";
import { unwrapOrElse } from "https://deno.land/x/optio/operators/extract.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(unwrapOrElse(Some(0), () => 2 ** 3), 0);
assertEquals(unwrapOrElse(None, () => 2 ** 3), 8);

Parameters

option: Option<T>
fn: () => T