Monoid overview

Added in v2.0.0


Table of contents


Monoid (interface)

Signature

export interface Monoid<A> extends Semigroup<A> {
  readonly empty: A
}

Added in v2.0.0

fold

Signature

export function fold<A>(M: Monoid<A>): (as: ReadonlyArray<A>) => A { ... }

Added in v2.0.0

getDualMonoid

Signature

export function getDualMonoid<A>(M: Monoid<A>): Monoid<A> { ... }

Added in v2.0.0

getEndomorphismMonoid

Signature

export function getEndomorphismMonoid<A = never>(): Monoid<Endomorphism<A>> { ... }

Added in v2.0.0

getFunctionMonoid

Signature

export function getFunctionMonoid<M>(M: Monoid<M>): <A = never>() => Monoid<(a: A) => M> { ... }

Added in v2.0.0

getJoinMonoid

Signature

export function getJoinMonoid<A>(B: Bounded<A>): Monoid<A> { ... }

Added in v2.0.0

getMeetMonoid

Signature

export function getMeetMonoid<A>(B: Bounded<A>): Monoid<A> { ... }

Added in v2.0.0

getStructMonoid

Signature

export function getStructMonoid<O extends ReadonlyRecord<string, any>>(
  monoids: { [K in keyof O]: Monoid<O[K]> }
): Monoid<O> { ... }

Added in v2.0.0

getTupleMonoid

Given a tuple of monoids returns a monoid for the tuple

Signature

export function getTupleMonoid<T extends ReadonlyArray<Monoid<any>>>(
  ...monoids: T
): Monoid<{ [K in keyof T]: T[K] extends Semigroup<infer A> ? A : never }> { ... }

Example

import { getTupleMonoid, monoidString, monoidSum, monoidAll } from 'fp-ts/lib/Monoid'

const M1 = getTupleMonoid(monoidString, monoidSum)
assert.deepStrictEqual(M1.concat(['a', 1], ['b', 2]), ['ab', 3])

const M2 = getTupleMonoid(monoidString, monoidSum, monoidAll)
assert.deepStrictEqual(M2.concat(['a', 1, true], ['b', 2, false]), ['ab', 3, false])

Added in v2.0.0

monoidAll

Boolean monoid under conjunction

Signature

export const monoidAll: Monoid<boolean> = ...

Added in v2.0.0

monoidAny

Boolean monoid under disjunction

Signature

export const monoidAny: Monoid<boolean> = ...

Added in v2.0.0

monoidProduct

Number monoid under multiplication

Signature

export const monoidProduct: Monoid<number> = ...

Added in v2.0.0

monoidString

Signature

export const monoidString: Monoid<string> = ...

Added in v2.0.0

monoidSum

Number monoid under addition

Signature

export const monoidSum: Monoid<number> = ...

Added in v2.0.0

monoidVoid

Signature

export const monoidVoid: Monoid<void> = ...

Added in v2.0.0