pub trait Monoid<'a>: Semigroup<'a> {
// Required method
fn empty() -> Self;
}Expand description
A type class for monoids.
Monoid extends Semigroup with an identity element. A monoid is a set
equipped with an associative binary operation and an identity element.
In functional programming, monoids are useful for combining values in a consistent way, especially when accumulating results or folding collections.
§Laws
Monoid instances must satisfy the following laws:
- Left identity:
append(empty(), x) = x. - Right identity:
append(x, empty()) = x. - Associativity:
append(append(x, y), z) = append(x, append(y, z)).
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.