← Back

Source

Semigroup

interface Semigroup<A> {
  readonly concat: (x: A, y: A) => A
}

Added in v1.0.0 (type class)

semigroupAll

Semigroup<boolean>

Added in v1.0.0 (instance)

Boolean semigroup under conjunction

semigroupAny

Semigroup<boolean>

Added in v1.0.0 (instance)

Boolean semigroup under disjunction

semigroupProduct

Semigroup<number>

Added in v1.0.0 (instance)

Number Semigroup under multiplication

semigroupString

Semigroup<string>

Added in v1.0.0 (instance)

semigroupSum

Semigroup<number>

Added in v1.0.0 (instance)

Number Semigroup under addition

semigroupVoid

Semigroup<void>

Added in v1.0.0 (instance)

fold

<A>(S: Semigroup<A>) => (a: A) => (as: Array<A>): A

Added in v1.0.0 (function)

getArraySemigroup

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

Added in v1.0.0 (function)

Semigroup under array concatenation

getDictionarySemigroup

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

Added in v1.4.0 (function)

Gets Semigroup instance for dictionaries given Semigroup instance for their values

Example

import { getDictionarySemigroup, semigroupSum } from 'fp-ts/lib/Semigroup'

const S = getDictionarySemigroup(semigroupSum)
assert.deepEqual(S.concat({ foo: 123 }, { foo: 456 }), { foo: 579 })

getDualSemigroup

<A>(S: Semigroup<A>): Semigroup<A>

Added in v1.0.0 (function)

getFirstSemigroup

<A = never>(): Semigroup<A>

Added in v1.0.0 (function)

getFunctionSemigroup

<S>(S: Semigroup<S>) => <A = never>(): Semigroup<(a: A) => S>

Added in v1.0.0 (function)

getJoinSemigroup

<A>(O: Ord<A>): Semigroup<A>

Added in v1.0.0 (function)

getLastSemigroup

<A = never>(): Semigroup<A>

Added in v1.0.0 (function)

getMeetSemigroup

<A>(O: Ord<A>): Semigroup<A>

Added in v1.0.0 (function)

getObjectSemigroup

<A extends object = never>(): Semigroup<A>

Added in v1.4.0 (function)

Gets Semigroup instance for objects of given type preserving their type

Example

import { getObjectSemigroup } from 'fp-ts/lib/Semigroup'

const S = getObjectSemigroup<{ foo: number }>()
assert.deepEqual(S.concat({ foo: 123 }, { foo: 456 }), { foo: 456 })

getProductSemigroup

<A, B>(SA: Semigroup<A>, SB: Semigroup<B>): Semigroup<[A, B]>

Added in v1.0.0 (function)

getRecordSemigroup

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

Added in v1.0.0 (function)