use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use parking_lot::Mutex;
use crate::macros::{
impl_arc_conversions,
impl_closure_trait,
impl_rc_conversions,
};
use crate::predicates::bi_predicate::{
ArcBiPredicate,
BiPredicate,
BoxBiPredicate,
RcBiPredicate,
};
use crate::transformers::{
bi_transformer_once::BoxBiTransformerOnce,
macros::{
impl_box_conditional_transformer,
impl_box_transformer_methods,
impl_conditional_transformer_clone,
impl_conditional_transformer_debug_display,
impl_shared_conditional_transformer,
impl_shared_transformer_methods,
impl_transformer_clone,
impl_transformer_common_methods,
impl_transformer_constant_method,
impl_transformer_debug_display,
},
stateful_transformer::StatefulTransformer,
};
mod box_stateful_bi_transformer;
pub use box_stateful_bi_transformer::BoxStatefulBiTransformer;
mod rc_stateful_bi_transformer;
pub use rc_stateful_bi_transformer::RcStatefulBiTransformer;
mod arc_stateful_bi_transformer;
pub use arc_stateful_bi_transformer::ArcStatefulBiTransformer;
mod fn_stateful_bi_transformer_ops;
pub use fn_stateful_bi_transformer_ops::FnStatefulBiTransformerOps;
mod stateful_binary_operator;
pub use stateful_binary_operator::StatefulBinaryOperator;
mod box_stateful_binary_operator;
pub use box_stateful_binary_operator::BoxStatefulBinaryOperator;
mod arc_stateful_binary_operator;
pub use arc_stateful_binary_operator::ArcStatefulBinaryOperator;
mod rc_stateful_binary_operator;
pub use rc_stateful_binary_operator::RcStatefulBinaryOperator;
mod box_conditional_stateful_bi_transformer;
pub use box_conditional_stateful_bi_transformer::BoxConditionalStatefulBiTransformer;
mod rc_conditional_stateful_bi_transformer;
pub use rc_conditional_stateful_bi_transformer::RcConditionalStatefulBiTransformer;
mod arc_conditional_stateful_bi_transformer;
pub use arc_conditional_stateful_bi_transformer::ArcConditionalStatefulBiTransformer;
pub trait StatefulBiTransformer<T, U, R> {
fn apply(&mut self, first: T, second: U) -> R;
fn into_box(self) -> BoxStatefulBiTransformer<T, U, R>
where
Self: Sized + 'static,
{
let mut trans = self;
BoxStatefulBiTransformer::new(move |x, y| trans.apply(x, y))
}
fn into_rc(self) -> RcStatefulBiTransformer<T, U, R>
where
Self: Sized + 'static,
{
let mut trans = self;
RcStatefulBiTransformer::new(move |x, y| trans.apply(x, y))
}
fn into_arc(self) -> ArcStatefulBiTransformer<T, U, R>
where
Self: Sized + Send + 'static,
{
let mut trans = self;
ArcStatefulBiTransformer::new(move |x, y| trans.apply(x, y))
}
fn into_fn(self) -> impl FnMut(T, U) -> R
where
Self: Sized + 'static,
{
let mut trans = self;
move |t, u| trans.apply(t, u)
}
fn into_mut_fn(self) -> impl FnMut(T, U) -> R
where
Self: Sized + 'static,
{
self.into_fn()
}
fn into_once(self) -> BoxBiTransformerOnce<T, U, R>
where
Self: Sized + 'static,
{
let mut trans = self;
BoxBiTransformerOnce::new(move |t, u| trans.apply(t, u))
}
fn to_box(&self) -> BoxStatefulBiTransformer<T, U, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcStatefulBiTransformer<T, U, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcStatefulBiTransformer<T, U, R>
where
Self: Sized + Clone + Send + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl FnMut(T, U) -> R
where
Self: Sized + Clone + 'static,
{
self.clone().into_fn()
}
fn to_mut_fn(&self) -> impl FnMut(T, U) -> R
where
Self: Sized + Clone + 'static,
{
self.to_fn()
}
fn to_once(&self) -> BoxBiTransformerOnce<T, U, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_once()
}
}