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§
Provided Methods§
Sourcefn join_assign(&mut self, other: &Self)
fn join_assign(&mut self, other: &Self)
In-place variant.
Sourcefn leq(&self, other: &Self) -> boolwhere
Self: PartialEq,
fn leq(&self, other: &Self) -> boolwhere
Self: PartialEq,
Derived partial order: x ≤ y iff x ∨ y = y.
Sourcefn join_all<I>(it: I) -> Option<Self>where
I: IntoIterator<Item = Self>,
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.