Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/result_js/operators/logical.ts>orElse

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

Calls fn if the result is Err, otherwise returns the Ok.

Examples

Example 1

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

declare const square: (value: number) => Ok<number>

assertEquals(orElse(Ok(3), square), Ok(3));
assertEquals(orElse(Err(2), square), Ok(4));

Parameters

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