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

x/optio/operators/logical.ts>orElse

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

Returns the option if it Some, otherwise calls fn and returns the result.

Examples

Example 1

import { orElse } from "https://deno.land/x/optio/operators/logical.ts";
import { None, Some } from "https://deno.land/x/optio/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(orElse(Some(0), () => Some(1)), Some(0));
assertEquals(orElse(None, () => Some(1)), Some(1));

Parameters

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