JoinSemilattice

Trait JoinSemilattice 

Source
pub trait JoinSemilattice: Sized {
    // Required method
    fn join(&self, other: &Self) -> Self;

    // Provided methods
    fn join_assign(&mut self, other: &Self) { ... }
    fn leq(&self, other: &Self) -> bool
       where Self: PartialEq { ... }
    fn join_all<I>(it: I) -> Option<Self>
       where I: IntoIterator<Item = Self> { ... }
}
Expand description

A join-semilattice: a type with an associative, commutative, idempotent binary operation.

Laws (not enforced by type system):

  • Associative: a.join(b).join(c) == a.join(b.join(c))
  • Commutative: a.join(b) == b.join(a)
  • Idempotent: a.join(a) == a

The join operation computes the least upper bound (supremum) in the induced partial order: x ≤ y iff x.join(y) == y.

§Example

use algebra_core::JoinSemilattice;
use std::collections::HashSet;

let a: HashSet<_> = [1, 2].into_iter().collect();
let b: HashSet<_> = [2, 3].into_iter().collect();

// join = union
let c = a.join(&b);
assert_eq!(c, [1, 2, 3].into_iter().collect());

// Idempotent
assert_eq!(a.join(&a), a);

Required Methods§

Source

fn join(&self, other: &Self) -> Self

The join (least upper bound).

Provided Methods§

Source

fn join_assign(&mut self, other: &Self)

In-place variant.

Source

fn leq(&self, other: &Self) -> bool
where Self: PartialEq,

Derived partial order: x ≤ y iff x ∨ y = y.

Source

fn join_all<I>(it: I) -> Option<Self>
where I: IntoIterator<Item = Self>,

Join a finite iterator of values. Returns None for empty iterators.

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 JoinSemilattice for bool

Source§

fn join(&self, other: &Self) -> Self

Source§

impl JoinSemilattice for ()

Source§

fn join(&self, _other: &Self) -> Self

Source§

impl<A> JoinSemilattice for (A,)
where A: JoinSemilattice,

Source§

fn join(&self, other: &Self) -> Self

Source§

impl<A, B> JoinSemilattice for (A, B)

Source§

fn join(&self, other: &Self) -> Self

Source§

impl<A, B, C> JoinSemilattice for (A, B, C)

Source§

fn join(&self, other: &Self) -> Self

Source§

impl<A, B, C, D> JoinSemilattice for (A, B, C, D)

Source§

fn join(&self, other: &Self) -> Self

Source§

impl<L: JoinSemilattice + Clone> JoinSemilattice for Option<L>

Source§

fn join(&self, other: &Self) -> Self

Source§

impl<T: Eq + Hash + Clone> JoinSemilattice for HashSet<T>

Source§

fn join(&self, other: &Self) -> Self

Source§

impl<T: Ord + Clone> JoinSemilattice for BTreeSet<T>

Source§

fn join(&self, other: &Self) -> Self

Implementors§