Skip to main content
Module

x/fun/mod.ts>option.getMonoid

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.getMonoid
import { option } from "https://deno.land/x/fun@v.2.0.0-alpha.11/mod.ts";
const { getMonoid } = option;

Create an instance of Monoid<Option> given an instance of Monoid.

Examples

Example 1

import * as O from "./option.ts";
import * as N from "./number.ts";
import * as M from "./monoid.ts";

const monoid = O.getMonoid(N.MonoidNumberSum);
const concatAll = M.concatAll(monoid);

const result1 = concatAll([O.some(1), O.some(2), O.some(3)]); // Some(6)
const result2 = concatAll([O.some(1), O.some(2), O.none]); // Some(3)
const result3 = concatAll([O.none, O.none, O.none]); // None
const result4 = concatAll([]); // None

Parameters

M: Monoid<A>

Returns

Monoid<Option<A>>