pub trait Semigroup {
// Required method
fn append<'a, ClonableFnBrand: 'a + ClonableFn>(
a: Self,
) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
where Self: Sized;
}
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, ClonableFnBrand: 'a + ClonableFn>(
a: Self,
) -> ApplyFn<'a, ClonableFnBrand, Self, Self>where
Self: Sized,
fn append<'a, ClonableFnBrand: 'a + ClonableFn>(
a: Self,
) -> ApplyFn<'a, ClonableFnBrand, Self, Self>where
Self: Sized,
Implementations on Foreign Types§
Source§impl Semigroup for String
impl Semigroup for String
Source§fn append<'a, ClonableFnBrand: 'a + ClonableFn>(
a: Self,
) -> ApplyFn<'a, ClonableFnBrand, Self, Self>where
Self: Sized,
fn append<'a, ClonableFnBrand: 'a + ClonableFn>(
a: Self,
) -> ApplyFn<'a, ClonableFnBrand, Self, Self>where
Self: Sized,
§Examples
use fp_library::{brands::RcFnBrand, functions::append};
use std::rc::Rc;
assert_eq!(
append::<RcFnBrand, String>("Hello, ".to_string())("World!".to_string()),
"Hello, World!"
);