Struct algae_rs::magma::UnitalMagma
source · pub struct UnitalMagma<'a, T> { /* private fields */ }Expand description
A set equipped with a binary operation and a specified identity element.
UnitalMagma is a representation of the abstract algebraic unital magma.
The existence of an identity element is all that is required of its
binary operation. Its construction requires a set (specifically an
AlgaeSet) and an identity-preserving BinaryOperation.
Examples
use algae_rs::algaeset::AlgaeSet;
use algae_rs::mapping::{BinaryOperation, IdentityOperation};
use algae_rs::magma::{Magmoid, UnitalMagma};
let mut add = IdentityOperation::new(&|a, b| a + b, 0);
let mut magma = UnitalMagma::new(
AlgaeSet::<i32>::all(),
&mut add,
0
);
let sum = magma.with(1, 2);
assert!(sum.is_ok());
assert!(sum.unwrap() == 3);
let mut bad_add = IdentityOperation::new(&|a, b| a + b, 3);
let mut bad_magma = UnitalMagma::new(
AlgaeSet::<i32>::all(),
&mut bad_add,
3
);
let bad_sum = bad_magma.with(2, 3);
assert!(bad_sum.is_err());