Trait Semigroup

Source
pub trait Semigroup {
    // Required method
    fn combine(self, other: Self) -> Self;

    // Provided methods
    fn combine_n(self, n: u32) -> Self
       where Self: Sized + Clone { ... }
    fn combine_all_option<I>(iter: I) -> Option<Self>
       where I: IntoIterator<Item = Self>,
             Self: Sized { ... }
}
Expand description

A Semigroup is an algebraic structure consisting of a set together with an associative binary operation. A Semigroup is a Monoid without an identity element.

Required Methods§

Source

fn combine(self, other: Self) -> Self

Associative operation which combines two values.

§Examples
use rust2fun::prelude::*;

assert_eq!(3, 1.combine(2));
assert_eq!(Some(1), Some(1).combine(None));

Provided Methods§

Source

fn combine_n(self, n: u32) -> Self
where Self: Sized + Clone,

Combine with itself n times.

§Examples
use rust2fun::prelude::*;

assert_eq!(1, 1.combine_n(0));
assert_eq!(2, 1.combine_n(1));
assert_eq!(3, 1.combine_n(2));
assert_eq!(4, Semigroup::combine_n(1, 3));
Source

fn combine_all_option<I>(iter: I) -> Option<Self>
where I: IntoIterator<Item = Self>, Self: Sized,

Combine all values in the iterator and return the total. If the sequence is empty, returns None. Otherwise, returns Some(total).

§Examples
use rust2fun::prelude::*;

assert_eq!(None, Semigroup::combine_all_option(Vec::<u8>::new()));
assert_eq!(Some(6), Semigroup::combine_all_option(vec![1,2,3]));
assert_eq!(
    Some("heyheyhey".to_owned()),
    Semigroup::combine_all_option(repeat("hey".to_owned()).take(3)));

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 f32

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for f64

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for i8

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for i16

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for i32

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for i64

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for i128

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for isize

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for u8

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for u16

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for u32

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for u64

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for u128

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for ()

Source§

fn combine(self, _other: Self) -> Self

Source§

impl Semigroup for usize

Source§

fn combine(self, other: Self) -> Self

Source§

impl Semigroup for String

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup> Semigroup for (A,)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup> Semigroup for (A, B)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup> Semigroup for (A, B, C)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup> Semigroup for (A, B, C, D)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup> Semigroup for (A, B, C, D, E)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup, F: Semigroup> Semigroup for (A, B, C, D, E, F)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup, F: Semigroup, G: Semigroup> Semigroup for (A, B, C, D, E, F, G)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup, F: Semigroup, G: Semigroup, H: Semigroup> Semigroup for (A, B, C, D, E, F, G, H)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup, F: Semigroup, G: Semigroup, H: Semigroup, I: Semigroup> Semigroup for (A, B, C, D, E, F, G, H, I)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup, F: Semigroup, G: Semigroup, H: Semigroup, I: Semigroup, J: Semigroup> Semigroup for (A, B, C, D, E, F, G, H, I, J)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup, F: Semigroup, G: Semigroup, H: Semigroup, I: Semigroup, J: Semigroup, K: Semigroup> Semigroup for (A, B, C, D, E, F, G, H, I, J, K)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup, E: Semigroup, F: Semigroup, G: Semigroup, H: Semigroup, I: Semigroup, J: Semigroup, K: Semigroup, L: Semigroup> Semigroup for (A, B, C, D, E, F, G, H, I, J, K, L)

Source§

fn combine(self, other: Self) -> Self

Source§

impl<K: Eq + Hash, V: Semigroup> Semigroup for HashMap<K, V>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T> Semigroup for LinkedList<T>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T> Semigroup for VecDeque<T>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T> Semigroup for Vec<T>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T> Semigroup for PhantomData<T>

Source§

fn combine(self, _other: Self) -> Self

Source§

impl<T: Eq + Hash> Semigroup for HashSet<T>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T: Ord> Semigroup for BinaryHeap<T>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T: Ord> Semigroup for BTreeSet<T>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T: Semigroup> Semigroup for Option<T>

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T: Semigroup> Semigroup for Box<T>

Source§

fn combine(self, other: Self) -> Self

Implementors§