use core::{marker::PhantomData, ops::ControlFlow};
use super::Aggregator;
pub struct TryFold<I> {
marker: PhantomData<I>,
}
pub trait TryFoldAggregator {
type Item;
type Acc;
type Break;
fn init() -> Self::Acc;
fn f(acc: Self::Acc, item: Self::Item) -> ControlFlow<Self::Break, Self::Acc>;
}
impl<I> Aggregator for TryFold<I>
where
I: TryFoldAggregator,
{
type Acc = I::Acc;
type Item = I::Item;
type Break = I::Break;
type Value = ControlFlow<I::Break, I::Acc>;
fn init() -> Self::Acc {
I::init()
}
fn try_fold(acc: Self::Acc, item: Self::Item) -> ControlFlow<Self::Break, Self::Acc> {
I::f(acc, item)
}
fn finalize(x: ControlFlow<Self::Break, Self::Acc>) -> Self::Value {
x
}
}