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) -> Selfwhere 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)));

Implementations on Foreign Types§

source§

impl Semigroup for f64

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 Semigroup for u128

source§

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

source§

impl Semigroup for u8

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<T> Semigroup for LinkedList<T>

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<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, E: Semigroup, F: Semigroup> Semigroup for (A, B, C, D, E, F)

source§

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

source§

impl Semigroup for f32

source§

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

source§

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

source§

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

source§

impl Semigroup for isize

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 Semigroup for String

source§

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

source§

impl Semigroup for u64

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 Semigroup for i64

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl Semigroup for usize

source§

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

source§

impl<T> Semigroup for PhantomData<T>

source§

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

source§

impl Semigroup for ()

source§

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

source§

impl Semigroup for i16

source§

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

source§

impl<T> Semigroup for VecDeque<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<A: Semigroup, B: Semigroup, C: Semigroup, D: Semigroup> Semigroup for (A, B, C, D)

source§

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

source§

impl Semigroup for i128

source§

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

source§

impl<T> Semigroup for Vec<T>

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 Semigroup for u32

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> Semigroup for (A, B)

source§

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

source§

impl Semigroup for u16

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 Semigroup for i8

source§

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

source§

impl Semigroup for i32

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<T: Semigroup> Semigroup for Box<T>

source§

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

Implementors§