Struct algae_rs::mapping::AssociativeOperation
source · pub struct AssociativeOperation<'a, T> { /* private fields */ }
Expand description
A function wrapper enforcing associativity.
Examples
let mut mul = AssociativeOperation::new(&|a, b| {
a * b
});
let six = mul.with(2, 3);
let twenty = mul.with(4, 5);
assert!(six.is_ok());
assert!(six.unwrap() == 6);
assert!(twenty.is_ok());
assert!(twenty.unwrap() == 20);
let mut div = AssociativeOperation::new(&|a, b| {
a / b
});
let whole_dividend = div.with(4.0, 2.0);
assert!(whole_dividend.is_ok());
assert!(whole_dividend.unwrap() == 2.0);
let fractional_dividend = div.with(3.0, 1.0);
assert!(fractional_dividend.is_err());
Implementations§
Trait Implementations§
source§impl<'a, T: Copy + PartialEq> BinaryOperation<T> for AssociativeOperation<'a, T>
impl<'a, T: Copy + PartialEq> BinaryOperation<T> for AssociativeOperation<'a, T>
source§fn operation(&self) -> &dyn Fn(T, T) -> T
fn operation(&self) -> &dyn Fn(T, T) -> T
Returns a reference to the function underlying the operation
source§fn properties(&self) -> Vec<PropertyType<T>>
fn properties(&self) -> Vec<PropertyType<T>>
Vec of all enforced properties
source§fn input_history(&self) -> &Vec<T>
fn input_history(&self) -> &Vec<T>
Returns a reference to a Vec of all previous inputs to the operation
source§fn is(&self, property: PropertyType<T>) -> bool
fn is(&self, property: PropertyType<T>) -> bool
Returns whether or not
property
is enforced by the given operation