Skip to main content
Module

x/result_js/mod.ts>unwrapOr

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

Returns the contained Ok value, otherwise defaultValue.

Examples

Example 1

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

assertEquals(unwrapOr(Ok(0), 1), 0);
assertEquals(unwrapOr(Err(1), 1), 1);

Parameters

result: Result<T, unknown>
defaultValue: T