pub trait Semigroup<'a>: Kind0 {
// Required method
fn append(a: Apply0<Self>) -> ArcFn<'a, Apply0<Self>, Apply0<Self>>;
}
Expand description
A typeclass for semigroups.
A Semigroup
is a set equipped with an associative binary operation.
This means for any elements a
, b
, and c
in the set, the operation
satisfies: (a <> b) <> c = a <> (b <> c)
.
In functional programming, semigroups are useful for combining values in a consistent way. They form the basis for more complex structures like monoids.
§Laws
Semigroup instances must satisfy the associative law:
- Associativity:
append(append(x)(y))(z) = append(x)(append(y)(z))
.
§Examples
Common semigroups include:
- Strings with concatenation.
- Numbers with addition.
- Numbers with multiplication.
- Lists with concatenation.
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.