Skip to main content
Module

x/fun/mod.ts>semigroup.first

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

Get an Semigroup over A that always returns the first parameter supplied to concat (confusingly this is actually the last parameter since concat is in curried form).

Examples

Example 1

import { first } from "./semigroup.ts";
import { pipe } from "./fn.ts";

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

const SemigroupPerson = first<Person>();

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

const firstPerson = pipe(
  octavia,
  SemigroupPerson.concat(kimbra),
  SemigroupPerson.concat(brandon),
); // firstPerson === octavia

Type Parameters

optional
A = never

Returns

Semigroup<A>