function unwrapOr
unwrapOr<O, U>(
outcome: O,
fallback: U
): Exclude<O, Any> | U

Returns the success value, or fallback if the outcome is a failure.

import * as Result from './index.ts';

const TooBig = Result.Failure.define('TooBig', (d: { raw: string }) => `${d.raw} > 65535`);
const parsePort = (raw: string): Result.Result<number, Result.Failure.Of<typeof TooBig>> =>
  Number(raw) > 65535 ? TooBig({ raw }) : Number(raw);

Result.unwrapOr(parsePort('99999'), 3000); // 3000

Type Parameters

Parameters

outcome: O
fallback: U

Return Type

Exclude<O, Any> | U

Usage

import { unwrapOr } from "lib/result/result.ts";