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
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));