Semigroup

Trait Semigroup 

Source
pub trait Semigroup {
    // Required method
    fn append(a: Self, b: Self) -> Self;
}
Expand description

A type class for types that support an associative binary operation.

Semigroup instances must satisfy the associative law:

  • Associativity: append(a, append(b, c)) = append(append(a, b), c).

Required Methods§

Source

fn append(a: Self, b: Self) -> Self

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

§Type Signature

forall a. Semigroup a => (a, a) -> a

§Parameters
  • a: The first value.
  • b: The second value.
§Returns

The combined value.

§Examples
use fp_library::classes::semigroup::Semigroup;
use fp_library::types::string; // Import Semigroup impl for String

let x = "Hello, ".to_string();
let y = "World!".to_string();
let z = String::append(x, y);
assert_eq!(z, "Hello, World!".to_string());

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.

Implementations on Foreign Types§

Source§

impl Semigroup for String

Source§

fn append(a: Self, b: Self) -> Self

Appends one string to another.

§Type Signature

forall. Semigroup String => (String, String) -> String

§Parameters
  • a: The first string.
  • b: The second string.
§Returns

The concatenated string.

§Examples
use fp_library::classes::semigroup::append;

assert_eq!(append("Hello, ".to_string(), "World!".to_string()), "Hello, World!".to_string());
Source§

impl<A: Clone> Semigroup for Vec<A>

Source§

fn append(a: Self, b: Self) -> Self

Appends one vector to another.

§Type Signature

forall a. Semigroup (Vec a) => (Vec a, Vec a) -> Vec a

§Parameters
  • a: The first vector.
  • b: The second vector.
§Returns

The concatenated vector.

§Examples
use fp_library::classes::semigroup::append;

assert_eq!(append(vec![1, 2], vec![3, 4]), vec![1, 2, 3, 4]);

Implementors§

Source§

impl<'a, C: Category, A: 'a> Semigroup for Endomorphism<'a, C, A>

Source§

impl<'a, CFB: 'a + ClonableFn, A: 'a> Semigroup for Endofunction<'a, CFB, A>

Source§

impl<'b, OnceBrand: 'b + Once, CFB: 'b + ClonableFn, A: Semigroup + Clone + 'b> Semigroup for Lazy<'b, OnceBrand, CFB, A>
where <OnceBrand as Once>::Of<A>: Clone,