use std::rc::Rc;
use std::sync::Arc;
use crate::macros::{
impl_arc_conversions,
impl_box_conversions,
impl_closure_trait,
impl_rc_conversions,
};
use crate::predicates::predicate::{
ArcPredicate,
BoxPredicate,
Predicate,
RcPredicate,
};
use crate::transformers::{
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,
},
transformer_once::BoxTransformerOnce,
};
mod box_transformer;
pub use box_transformer::BoxTransformer;
mod rc_transformer;
pub use rc_transformer::RcTransformer;
mod arc_transformer;
pub use arc_transformer::ArcTransformer;
mod fn_transformer_ops;
pub use fn_transformer_ops::FnTransformerOps;
mod unary_operator;
pub use unary_operator::UnaryOperator;
mod box_unary_operator;
pub use box_unary_operator::BoxUnaryOperator;
mod arc_unary_operator;
pub use arc_unary_operator::ArcUnaryOperator;
mod rc_unary_operator;
pub use rc_unary_operator::RcUnaryOperator;
mod box_conditional_transformer;
pub use box_conditional_transformer::BoxConditionalTransformer;
mod rc_conditional_transformer;
pub use rc_conditional_transformer::RcConditionalTransformer;
mod arc_conditional_transformer;
pub use arc_conditional_transformer::ArcConditionalTransformer;
pub trait Transformer<T, R> {
fn apply(&self, input: T) -> R;
fn into_box(self) -> BoxTransformer<T, R>
where
Self: Sized + 'static,
{
BoxTransformer::new(move |x| self.apply(x))
}
fn into_rc(self) -> RcTransformer<T, R>
where
Self: Sized + 'static,
{
RcTransformer::new(move |x| self.apply(x))
}
fn into_arc(self) -> ArcTransformer<T, R>
where
Self: Sized + Send + Sync + 'static,
{
ArcTransformer::new(move |x| self.apply(x))
}
fn into_fn(self) -> impl Fn(T) -> R
where
Self: Sized + 'static,
{
move |t: T| self.apply(t)
}
fn into_once(self) -> BoxTransformerOnce<T, R>
where
Self: Sized + 'static,
{
BoxTransformerOnce::new(move |t| self.apply(t))
}
fn to_box(&self) -> BoxTransformer<T, R>
where
Self: Clone + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcTransformer<T, R>
where
Self: Clone + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcTransformer<T, R>
where
Self: Clone + Send + Sync + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl Fn(T) -> R
where
Self: Clone + 'static,
{
self.clone().into_fn()
}
fn to_once(&self) -> BoxTransformerOnce<T, R>
where
Self: Clone + 'static,
{
self.clone().into_once()
}
}