Skip to main content
Module

x/result_js/mod.ts>unwrapOrElse

Minimum result type port of Rust
Latest
function unwrapOrElse
import { unwrapOrElse } from "https://deno.land/x/result_js@2.0.0/mod.ts";

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

Examples

Example 1

import { Ok, Err } from "https://deno.land/x/result_js/spec.ts";
import { unwrapOrElse } from "https://deno.land/x/result_js/operators/extract.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(unwrapOrElse(Ok(0), () => 2 ** 3), 0);
assertEquals(unwrapOrElse(Err(1), () => 2 ** 3), 8);

Parameters

result: Result<T, E>
fn: (value: E) => T