use std::any::Any;
use tinyflow_api::functions::{FilterFunction, FlatMapFunction, MapFunction};
use super::middle_tail_step;
middle_tail_step! {
struct MapChainSegment<T, O, F>;
marker: (T, O);
where {
T: Send + 'static,
O: Clone + Send + 'static,
F: MapFunction<T, O> + Clone + Send + 'static,
}
process { |this, data, runtime| {
let out = this.function.map(data, runtime).await?;
Ok(vec![Box::new(out) as Box<dyn Any + Send>])
}}
factory map_chain_factory
}
middle_tail_step! {
struct FilterChainSegment<T, F>;
marker: T;
where {
T: Clone + Send + 'static,
F: FilterFunction<T> + Clone + Send + 'static,
}
process { |this, data, runtime| {
if this.function.filter(&data, runtime).await? {
Ok(vec![Box::new(data) as Box<dyn Any + Send>])
} else {
Ok(vec![])
}
}}
factory filter_chain_factory
}
middle_tail_step! {
struct FlatMapChainSegment<T, O, F>;
marker: (T, O);
where {
T: Send + 'static,
O: Clone + Send + 'static,
F: FlatMapFunction<T, O> + Clone + Send + 'static,
}
process { |this, data, runtime| {
let outs = this.function.flat_map(data, runtime).await?;
Ok(outs
.into_iter()
.map(|d| Box::new(d) as Box<dyn Any + Send>)
.collect::<Vec<_>>())
}}
factory flat_map_chain_factory
}