Trait naan::semigroup::Semigroup

source ·
pub trait Semigroup {
    // Required method
    fn append(self, b: Self) -> Self;
}
Expand description

Semigroup defines some associative operation that can be done to 2 instances of a type.

Examples

  • String’s semigroup implementation concatenates the two strings.
  • Vec’s semigroup implementation concatenates the two Vecs.

Laws

Implementations of Semigroup must be associative, e.g.

use naan::prelude::*;

let a = || vec![1u8, 2];
let b = || vec![3u8, 4];
let c = || vec![5u8, 6];

assert_eq!(a().append(b().append(c())), a().append(b()).append(c()));

Required Methods§

source

fn append(self, b: Self) -> Self

Implementations on Foreign Types§

source§

impl<A> Semigroup for Vec<A>

source§

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

source§

impl Semigroup for String

source§

fn append(self, b: Self) -> Self

source§

impl<A> Semigroup for Option<A>where A: Semigroup,

source§

fn append(self, b: Self) -> Self

source§

impl<K, A> Semigroup for BTreeMap<K, A>where K: Ord,

source§

fn append(self, b: Self) -> Self

source§

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

source§

fn append(self, b: Self) -> Self

source§

impl<A, const N: usize> Semigroup for ArrayVec<[Option<A>; N]>

source§

fn append(self, b: Self) -> Self

Implementors§

source§

impl<T> Semigroup for Id<T>where T: Semigroup,