Skip to main content
Module

x/fun/semigroup.ts>dual

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 dual
import { dual } from "https://deno.land/x/fun@v2.0.0-alpha.10/semigroup.ts";

Get the "Dual" of an existing Semigroup. This effectively reverses the order of the input semigroup's application. For example, the dual of the "first" semigroup is the "last" semigroup. The dual of (boolean, ||) is itself.

Examples

Example 1

import * as SG from "./semigroup.ts";
import { pipe } from "./fn.ts";

type Person = { name: string, age: number };

const last = SG.last<Person>();
const dual = SG.dual(last);

const octavia: Person = { name: "Octavia", age: 42 };
const kimbra: Person = { name: "Kimbra", age: 32 };
const brandon: Person = { name: "Brandon", age: 37 };

const dualPerson = pipe(
  octavia,
  dual.concat(kimbra),
  dual.concat(brandon),
); // dualPerson === octavia