pub trait Monoid: Semigroup {
// Required method
fn empty() -> Self;
// Provided methods
fn is_empty(&self) -> bool
where Self: Eq + Sized { ... }
fn combine_all<I>(iter: I) -> Self
where I: IntoIterator<Item = Self>,
Self: Sized { ... }
}
Expand description
A Monoid
is a Semigroup
with an identity element.
Required Methods§
Provided Methods§
sourcefn is_empty(&self) -> boolwhere
Self: Eq + Sized,
fn is_empty(&self) -> boolwhere Self: Eq + Sized,
Returns true if the value is the identity element.
Examples
use rust2fun::prelude::*;
assert!(i32::empty().is_empty());
assert!(!1.is_empty());
sourcefn combine_all<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = Self>,
Self: Sized,
fn combine_all<I>(iter: I) -> Selfwhere I: IntoIterator<Item = Self>, Self: Sized,
Given an iterator of Monoid
s, combine them all into one.
If the sequence is empty, returns Monoid::empty()
.
Examples
use rust2fun::prelude::*;
assert_eq!(0, Monoid::combine_all(Vec::<u8>::new()));
assert_eq!(6, Monoid::combine_all(vec![1,2,3]));