← Back

Source

Monoid

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

Added in v1.0.0 (type class)

monoidAll

Monoid<boolean>

Added in v1.0.0 (instance)

Boolean monoid under conjunction

monoidAny

Monoid<boolean>

Added in v1.0.0 (instance)

Boolean monoid under disjunction

monoidProduct

Monoid<number>

Added in v1.0.0 (instance)

Number monoid under multiplication

monoidString

Monoid<string>

Added in v1.0.0 (instance)

monoidSum

Monoid<number>

Added in v1.0.0 (instance)

Number monoid under addition

monoidVoid

Monoid<void>

Added in v1.0.0 (instance)

unsafeMonoidArray

Monoid<Array<any>>

Added in v1.0.0 (instance)

fold

<A>(M: Monoid<A>): ((as: Array<A>) => A)

Added in v1.0.0 (function)

getArrayMonoid

<A = never>(): Monoid<Array<A>>

Added in v1.0.0 (function)

Monoid under array concatenation (Array<any>)

getDictionaryMonoid

<A>(S: Semigroup<A>): Monoid<{ [key: string]: A }>

Added in v1.4.0 (function)

Gets Monoid instance for dictionaries given Semigroup instance for their values

Example

import { getDictionaryMonoid, fold } from 'fp-ts/lib/Monoid'
import { semigroupSum } from 'fp-ts/lib/Semigroup'

const M = getDictionaryMonoid(semigroupSum)
assert.deepEqual(fold(M)([{ foo: 123 }, { foo: 456 }]), { foo: 579 })

getDualMonoid

<A>(M: Monoid<A>): Monoid<A>

Added in v1.0.0 (function)

getEndomorphismMonoid

<A = never>(): Monoid<Endomorphism<A>>

Added in v1.0.0 (function)

getFunctionMonoid

<M>(M: Monoid<M>) => <A = never>(): Monoid<(a: A) => M>

Added in v1.0.0 (function)

getJoinMonoid

<A>(B: Bounded<A>): Monoid<A>

Added in v1.9.0 (function)

getMeetMonoid

<A>(B: Bounded<A>): Monoid<A>

Added in v1.9.0 (function)

getProductMonoid

<A, B>(MA: Monoid<A>, MB: Monoid<B>): Monoid<[A, B]>

Added in v1.0.0 (function)

getRecordMonoid

<O extends { [key: string]: any }>(
  monoids: { [K in keyof O]: Monoid<O[K]> }
): Monoid<O>

Added in v1.0.0 (function)