import { option } from "https://deno.land/x/fun@v2.0.0-alpha.6/mod.ts";
const { fold } = option;
fold is 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
const toNumber = fold((a: number) => a, () => 0);
const a = toNumber(some(1)); // 1
const b = toNumber(none); // 0
const toNumber = fold((a: number) => a, () => 0); const a = toNumber(some(1)); // 1 const b = toNumber(none); // 0