Semigroup

Trait Semigroup 

Source
pub trait Semigroup<'b> {
    // Required method
    fn append<'a, ClonableFnBrand: 'a + 'b + ClonableFn>(
        a: Self,
    ) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
       where Self: Sized,
             'b: 'a;
}
Expand description

A type class for semigroups.

A Semigroup is a set equipped with an associative binary operation.

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(a)(b))(c) = append(a)(append(b)(c)).

Required Methods§

Source

fn append<'a, ClonableFnBrand: 'a + 'b + ClonableFn>( a: Self, ) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
where Self: Sized, 'b: 'a,

Associative operation that combines two values of the same type.

§Type Signature

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.

Implementations on Foreign Types§

Source§

impl<'b> Semigroup<'b> for String

Source§

fn append<'a, ClonableFnBrand: 'a + 'b + ClonableFn>( a: Self, ) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
where Self: Sized, 'b: 'a,

§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!"
);
Source§

impl<'b, A> Semigroup<'b> for Vec<A>
where A: Clone,

Source§

fn append<'a, ClonableFnBrand: 'a + ClonableFn>( a: Self, ) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
where Self: Sized,

§Examples
use fp_library::{brands::RcFnBrand, functions::append};

assert_eq!(
    append::<RcFnBrand, Vec<_>>(vec![true])(vec![false]),
    vec![true, false]
);
Source§

impl<'b, A: 'b + Clone, B: Semigroup<'b> + 'b> Semigroup<'b> for Rc<dyn Fn(A) -> B + 'b>

Source§

fn append<'a, ClonableFnBrand: 'a + 'b + ClonableFn>( a: Self, ) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
where Self: Sized, 'b: 'a,

Source§

impl<'b, A: 'b + Clone, B: Semigroup<'b> + 'b> Semigroup<'b> for Arc<dyn Fn(A) -> B + 'b>

Source§

fn append<'a, ClonableFnBrand: 'a + 'b + ClonableFn>( a: Self, ) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
where Self: Sized, 'b: 'a,

Implementors§

Source§

impl<'b, CategoryBrand: 'b + Category, A> Semigroup<'b> for Endomorphism<'b, CategoryBrand, A>
where Apply1L2T<'b, CategoryBrand, A, A>: Clone,

Source§

impl<'b, ClonableFnBrand: 'b + ClonableFn, A> Semigroup<'b> for Endofunction<'b, ClonableFnBrand, A>