Trait an_rope::metric::Monoid
[−]
[src]
pub trait Monoid: Add<Self, Output = Self> + Default + Sized {
fn accumulate<F>(xs: F) -> Self
where
F: Iterator<Item = Self>,
Self: Sized,
{ ... }
}The class of monoids
Monoids are types with an accumulative binary operation that has an identity.
Technically, Add<Self, Output=Self> is standing in for "semigroup" here,
while Default is standing in for "identity"1.
An instance M should satisfy the following laws:
- x
.add(M::default())= x - M
::default().add(x)= x - x
.add(y.add(z))= z.add(x.add(y)) - M
::accumulate(a)= a.fold(M::default,M::sum)
-
A mathematician might point out that it might be more correct to represent the "identity" operation using the
Zerotrait rather thanDefault, as the documentation forZeronotes that "[t]his trait is intended for use in conjunction withAdd, as an identity". However, theZerotrait is marked as unstable, so it would only be useable on nightly Rust, and its use is deprecated. Thus,Default. ↩
Provided Methods
fn accumulate<F>(xs: F) -> Self where
F: Iterator<Item = Self>,
Self: Sized,
F: Iterator<Item = Self>,
Self: Sized,
Implementations on Foreign Types
impl Monoid for usize[src]
fn accumulate<F>(xs: F) -> Self where
F: Iterator<Item = Self>,
Self: Sized, [src]
F: Iterator<Item = Self>,
Self: Sized,