Monoid overview

Added in v2.0.0


Table of contents


combinators

getDualMonoid

The dual of a Monoid, obtained by swapping the arguments of concat.

Signature

export declare function getDualMonoid<A>(M: Monoid<A>): Monoid<A>

Example

import { getDualMonoid, monoidString } from 'fp-ts/lib/Monoid'

assert.deepStrictEqual(getDualMonoid(monoidString).concat('a', 'b'), 'ba')

Added in v2.0.0

instances

getEndomorphismMonoid

Signature

export declare function getEndomorphismMonoid<A = never>(): Monoid<Endomorphism<A>>

Added in v2.0.0

getFunctionMonoid

Signature

export declare function getFunctionMonoid<M>(M: Monoid<M>): <A = never>() => Monoid<(a: A) => M>

Added in v2.0.0

getJoinMonoid

Signature

export declare function getJoinMonoid<A>(B: Bounded<A>): Monoid<A>

Added in v2.0.0

getMeetMonoid

Signature

export declare function getMeetMonoid<A>(B: Bounded<A>): Monoid<A>

Added in v2.0.0

getStructMonoid

Signature

export declare 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 declare 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 declare const monoidAll: Monoid<boolean>

Added in v2.0.0

monoidAny

Boolean monoid under disjunction

Signature

export declare const monoidAny: Monoid<boolean>

Added in v2.0.0

monoidProduct

Number monoid under multiplication

Signature

export declare const monoidProduct: Monoid<number>

Added in v2.0.0

monoidString

Signature

export declare const monoidString: Monoid<string>

Added in v2.0.0

monoidSum

Number monoid under addition

Signature

export declare const monoidSum: Monoid<number>

Added in v2.0.0

monoidVoid

Signature

export declare const monoidVoid: Monoid<void>

Added in v2.0.0

type classes

Monoid (interface)

Signature

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

Added in v2.0.0

utils

fold

Signature

export declare function fold<A>(M: Monoid<A>): (as: ReadonlyArray<A>) => A

Added in v2.0.0