Monoid overview
Added in v1.0.0
Table of contents
combinators
array
Given a type A
, this function creates and returns a Semigroup
for ReadonlyArray<A>
.
The empty
value is the empty array.
Signature
export declare const array: <A>() => Monoid<readonly A[]>
Added in v1.0.0
reverse
The dual of a Monoid
, obtained by swapping the arguments of combine
.
Signature
export declare const reverse: <A>(M: Monoid<A>) => Monoid<A>
Added in v1.0.0
struct
This function creates and returns a new Monoid
for a struct of values based on the given Monoid
s for each property in the struct. The returned Monoid
combines two structs of the same type by applying the corresponding Monoid
passed as arguments to each property in the struct.
The empty
value of the returned Monoid
is a struct where each property is the empty
value of the corresponding Monoid
in the input monoids
object.
It is useful when you need to combine two structs of the same type and you have a specific way of combining each property of the struct.
Signature
export declare const struct: <R extends { readonly [x: string]: Monoid<any> }>(
fields: R
) => Monoid<{ readonly [K in keyof R]: [R[K]] extends [Monoid<infer A>] ? A : never }>
Added in v1.0.0
tuple
Similar to Promise.all
but operates on Monoid
s.
[Monoid<A>, Monoid<B>, ...] -> Monoid<[A, B, ...]>
This function creates and returns a new Monoid
for a tuple of values based on the given Monoid
s for each element in the tuple. The returned Monoid
combines two tuples of the same type by applying the corresponding Monoid
passed as arguments to each element in the tuple.
The empty
value of the returned Monoid
is the tuple of empty
values of the input Monoid
s.
It is useful when you need to combine two tuples of the same type and you have a specific way of combining each element of the tuple.
Signature
export declare const tuple: <T extends readonly Monoid<any>[]>(
...elements: T
) => Monoid<{ readonly [I in keyof T]: [T[I]] extends [Monoid<infer A>] ? A : never }>
Added in v1.0.0
constructors
fromSemigroup
Signature
export declare const fromSemigroup: <A>(S: Semigroup<A>, empty: A) => Monoid<A>
Added in v1.0.0
max
Get a monoid where combine
will return the maximum, based on the provided bounded order.
The empty
value is the minimum
value.
Signature
export declare const max: <A>(B: Bounded<A>) => Monoid<A>
Added in v1.0.0
min
Get a monoid where combine
will return the minimum, based on the provided bounded order.
The empty
value is the maxBound
value.
Signature
export declare const min: <A>(B: Bounded<A>) => Monoid<A>
Added in v1.0.0
instances
bigintMultiply
bigint
monoid under multiplication.
The empty
value is 1n
.
Signature
export declare const bigintMultiply: Monoid<bigint>
Added in v1.0.0
bigintSum
number
monoid under addition.
The bigint
value is 0n
.
Signature
export declare const bigintSum: Monoid<bigint>
Added in v1.0.0
booleanAll
boolean
monoid under conjunction.
The empty
value is true
.
Signature
export declare const booleanAll: Monoid<boolean>
Added in v1.0.0
booleanAny
boolean
monoid under disjunction.
The empty
value is false
.
Signature
export declare const booleanAny: Monoid<boolean>
Added in v1.0.0
booleanEqv
boolean
monoid under equivalence.
The empty
value is true
.
Signature
export declare const booleanEqv: Monoid<boolean>
Added in v1.0.0
booleanXor
boolean
monoid under exclusive disjunction.
The empty
value is false
.
Signature
export declare const booleanXor: Monoid<boolean>
Added in v1.0.0
numberMultiply
number
monoid under multiplication.
The empty
value is 1
.
Signature
export declare const numberMultiply: Monoid<number>
Added in v1.0.0
numberSum
number
monoid under addition.
The empty
value is 0
.
Signature
export declare const numberSum: Monoid<number>
Added in v1.0.0
string
Signature
export declare const string: Monoid<string>
Added in v1.0.0
type class
Monoid (interface)
Signature
export interface Monoid<A> extends Semigroup<A> {
readonly empty: A
readonly combineAll: (collection: Iterable<A>) => A
}
Added in v1.0.0