method Result.prototype.match
Result.prototype.match<U>(pattern: { ok: (value: T) => U; err: (error: E) => U; }): U

Pattern matching for Results - handle both Ok and Err cases.

Examples

Example 1

const message = result.match({
  ok: (value) => `Success: ${value}`,
  err: (error) => `Error: ${error.message}`
});

Type Parameters

The type of the return value

Parameters

pattern: { ok: (value: T) => U; err: (error: E) => U; }

Object with ok and err handler functions

Return Type

The result of calling either the ok or err handler

Usage

import { Result } from "result/mod.ts";