Skip to main content
Module

x/fun/mod.ts>option.match

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.match
import { option } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { match } = option;

The match functionis the standard catamorphism on an Option. It operates like a switch case operator over the two potential cases for an Option type. One supplies functions for handling the Some case and the None case with matching return types and fold calls the correct function for the given option.

Examples

Example 1

import * as O from "./option.ts";

const toNumber = O.match(() => 0, n => n);

const result1 = toNumber(O.none); // 0
const result2 = toNumber(O.some(1)); // 1

Parameters

onNone: () => B
onSome: (a: A) => B