use super::{collector::*, mapper::Mapper};
pub struct FnCollector<'a,TFn>(pub &'a TFn);
impl<'a,T,TFn> Mapper<T> for FnCollector<'a,TFn> {
type Output=T;
fn map(&self,value:T)->Self::Output {
value
}
}
impl<'a,Input,Next,Output,TFn> Collector<Input,Next> for FnCollector<'a,TFn>
where TFn:Fn(Input,Next)->Output
{
type Output=Output;
fn collect(&self,value:Input,next:Next)-><Self as Collector<Input,Next>>::Output {
(self.0)(value,next)
}
}
pub struct MapperCollector<TMapper,TCollector>(pub TMapper,pub TCollector);
impl<'a,TMapper,TCollector,Input> Mapper<Input> for MapperCollector<TMapper,TCollector>
where TMapper:Mapper<Input>,
TCollector:Mapper< <TMapper as Mapper<Input>>::Output >
{
type Output=< TCollector as Mapper< <TMapper as Mapper<Input>>::Output >>::Output;
fn map(&self,value:Input)->Self::Output {
self.1.map(self.0.map(value))
}
}
impl <'a,TMapper,TCollector,Input,TNext> Collector<Input,TNext> for MapperCollector<TMapper,TCollector>
where TMapper:Mapper<Input>,
TCollector:Collector<<TMapper as Mapper<Input>>::Output,TNext>
{
type Output= <TCollector as Collector<<TMapper as Mapper<Input>>::Output,TNext>>::Output ;
fn collect(&self,value:Input,next:TNext)-><Self as Collector<Input,TNext>>::Output {
let v1=self.0.map(value);
let r=self.1.collect(v1, next);
return r;
}
}
impl Mapper<()> for () {
type Output=();
fn map(&self,_value:())->() {()}
}
impl Collector<(),()> for () {
type Output=();
fn collect(&self,_value:(),_next:())->(){()}
}