Skip to main content
Module

x/fun/mod.ts>option.fold

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.fold
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

Parameters

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