Skip to main content
Module

x/fun/mod.ts>option.alt

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function option.alt
import { option } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { alt } = option;

Replace an first with second if first is None. This allows one to offer a a replacement or default.

Examples

Example 1

import * as O from "./option.ts";
import { pipe } from "./fn.ts";

const result1 = pipe(O.some(1), O.alt(O.some(2))); // Some(1);
const result2 = pipe(O.some(1), O.alt(O.constNone())); // Some(1);
const result3 = pipe(O.none, O.alt(O.some(2))); // Some(2);
const result4 = pipe(O.none, O.alt(O.none)); // None

Returns

(first: Option<A>) => Option<A>