Monoid.ts overview
Since v0.24.0
Exports Grouped by Category
combinators
array
Given a type A, this function creates and returns a Semigroup for ReadonlyArray<A>.
The empty value is the empty array.
Signature
declare const array: <A>() => Monoid<ReadonlyArray<A>>
Since v0.24.0
reverse
The dual of a Monoid, obtained by swapping the arguments of combine.
Signature
declare const reverse: <A>(M: Monoid<A>) => Monoid<A>
Since v0.24.0
struct
This function creates and returns a new Monoid for a struct of values based on the given Monoids 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
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 }>
Since v0.24.0
tuple
Similar to Promise.all but operates on Monoids.
[Monoid<A>, Monoid<B>, ...] -> Monoid<[A, B, ...]>
This function creates and returns a new Monoid for a tuple of values based on the given Monoids 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 Monoids.
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
declare const tuple: <T extends ReadonlyArray<Monoid<any>>>(
...elements: T
) => Monoid<{ readonly [I in keyof T]: [T[I]] extends [Monoid<infer A>] ? A : never }>
Since v0.24.0
constructors
fromSemigroup
Signature
declare const fromSemigroup: <A>(S: Semigroup<A>, empty: Monoid<A>["empty"]) => Monoid<A>
Since v0.24.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
declare const max: <A>(B: Bounded<A>) => Monoid<A>
Since v0.24.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
declare const min: <A>(B: Bounded<A>) => Monoid<A>
Since v0.24.0
type class
Monoid (interface)
Signature
export interface Monoid<A> extends Semigroup<A> {
readonly empty: A
readonly combineAll: (collection: Iterable<A>) => A
}
Since v0.24.0