Semigroup

Trait Semigroup 

Source
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§

Source

fn append(a: Apply0<Self>) -> ArcFn<'a, Apply0<Self>, Apply0<Self>>

Associative operation that combines two values of the same type.

§Type Signature

forall a. Semigroup a => a -> a -> a

§Parameters
  • a: First value to combine.
  • b: Second value to combine.
§Returns

The result of combining the two values using the semigroup operation.

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.

Implementors§

Source§

impl<'a> Semigroup<'a> for StringBrand

Source§

impl<'a, A> Semigroup<'a> for EndomorphismBrand<'a, A>

Source§

impl<'a, A> Semigroup<'a> for ConcreteVecBrand<A>
where A: 'a + Clone,