pub trait Semigroup: Kind<()> {
// Required method
fn append(a: Apply<Self, ()>) -> impl Fn(Apply<Self, ()>) -> Apply<Self, ()>
where Apply<Self, ()>: Clone;
}
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§
Sourcefn append(a: Apply<Self, ()>) -> impl Fn(Apply<Self, ()>) -> Apply<Self, ()>
fn append(a: Apply<Self, ()>) -> impl Fn(Apply<Self, ()>) -> Apply<Self, ()>
Associative operation that combines two values of the same type.
§Parameters
a
: First value to combine.
§Returns
A function that takes in the second value to combine and returns the result of combining the two values using the semigroup operation.
§Type Signature
forall a. Semigroup a => a -> a -> a
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.