use crate::errors::Result;
pub trait Aggregate<S>: Sized {
fn from_shares<T>(iter: T) -> Result<Self>
where
T: IntoIterator<Item = S>;
}
impl<S, A> Aggregate<Result<S>> for A
where
A: Aggregate<S>,
{
fn from_shares<T>(iter: T) -> Result<Self>
where
T: IntoIterator<Item = Result<S>>,
{
A::from_shares(iter.into_iter().collect::<Result<Vec<_>>>()?)
}
}
pub trait AggregateIter {
type Share;
fn aggregate<A>(self) -> Result<A>
where
A: Aggregate<Self::Share>;
}
impl<I: Iterator<Item = S>, S> AggregateIter for I {
type Share = S;
fn aggregate<A>(self) -> Result<A>
where
A: Aggregate<Self::Share>,
{
Aggregate::from_shares(self)
}
}