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§
Sourcefn append(a: Self, b: Self) -> Self
fn append(a: Self, b: Self) -> Self
The result of combining the two values using the semigroup operation.
This method combines two values of the same type into a single value of that type.
§Type Signature
forall self. Semigroup self => (self, self) -> self
§Parameters
a: The first value.b: The second value.
§Returns
The combined value.
§Examples
use fp_library::functions::*;
let x = "Hello, ".to_string();
let y = "World!".to_string();
let z = 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
impl Semigroup for String
Source§fn append(a: Self, b: Self) -> Self
fn append(a: Self, b: Self) -> Self
The result of combining two strings.
This method combines two strings into a single string.
§Type Signature
forall self. (self, self) -> self
§Parameters
a: The first string.b: The second string.
§Returns
The combined string.
§Examples
use fp_library::functions::*;
let s1 = "Hello, ".to_string();
let s2 = "World!".to_string();
let result = append::<_>(s1, s2);
assert_eq!(result, "Hello, World!");Source§impl<A: Clone> Semigroup for Vec<A>
impl<A: Clone> Semigroup for Vec<A>
Source§fn append(a: Self, b: Self) -> Self
fn append(a: Self, b: Self) -> Self
Appends one vector to another.
This method concatenates two vectors.
§Type Signature
forall self. Semigroup self => (self, self) -> self
§Type Parameters
A: The type of the elements in the vector.
§Parameters
a: The first vector.b: The second vector.
§Returns
The concatenated vector.
§Examples
use fp_library::functions::*;
assert_eq!(append(vec![1, 2], vec![3, 4]), vec![1, 2, 3, 4]);