Skip to main content
Module

x/fun/semigroup.ts>tuple

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

Get a Semigroup from a tuple of semigroups. The resulting semigroup will operate over tuples applying the input semigroups applying each based on its position,

Examples

Example 1

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

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

const first = SG.first<Person>();
const last = SG.last<Person>();
const { concat } = SG.tuple(first, last);

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

const tuplePeople = pipe(
  [octavia, octavia],
  concat([kimbra, kimbra]),
  concat([brandon, brandon]),
); // tuplePeople === [octavia, brandon]

Parameters

...semigroups: T

Returns

Semigroup<readonly [K in keyof T]: TypeOf<T[K]>>