use super::{
BoxStatefulPredicate,
StatefulPredicate,
};
pub trait FnStatefulPredicateOps<T>: FnMut(&T) -> bool + Sized {
#[inline]
fn and<P>(mut self, mut other: P) -> BoxStatefulPredicate<T>
where
Self: 'static,
P: StatefulPredicate<T> + 'static,
T: 'static,
{
BoxStatefulPredicate::new(move |value: &T| self(value) && other.test(value))
}
#[inline]
fn or<P>(mut self, mut other: P) -> BoxStatefulPredicate<T>
where
Self: 'static,
P: StatefulPredicate<T> + 'static,
T: 'static,
{
BoxStatefulPredicate::new(move |value: &T| self(value) || other.test(value))
}
#[inline]
fn not(mut self) -> BoxStatefulPredicate<T>
where
Self: 'static,
T: 'static,
{
BoxStatefulPredicate::new(move |value: &T| !self(value))
}
#[inline]
fn nand<P>(mut self, mut other: P) -> BoxStatefulPredicate<T>
where
Self: 'static,
P: StatefulPredicate<T> + 'static,
T: 'static,
{
BoxStatefulPredicate::new(move |value: &T| !(self(value) && other.test(value)))
}
#[inline]
fn xor<P>(mut self, mut other: P) -> BoxStatefulPredicate<T>
where
Self: 'static,
P: StatefulPredicate<T> + 'static,
T: 'static,
{
BoxStatefulPredicate::new(move |value: &T| self(value) ^ other.test(value))
}
#[inline]
fn nor<P>(mut self, mut other: P) -> BoxStatefulPredicate<T>
where
Self: 'static,
P: StatefulPredicate<T> + 'static,
T: 'static,
{
BoxStatefulPredicate::new(move |value: &T| !(self(value) || other.test(value)))
}
}
impl<T, F> FnStatefulPredicateOps<T> for F where F: FnMut(&T) -> bool {}