#![doc = include_str!("../README.md")]
use combinator::{filter::AsyncFilter, map::AsyncMap};
pub mod combinator;
pub mod iter;
mod option;
mod result;
pub use iter::AsyncIterator;
pub use option::AsyncOptionTools;
pub use result::AsyncResultTools;
use crate::iter::process_result::ProcessResults;
pub trait AsyncIterTools: AsyncIterator {
fn for_each_async<F, Fut>(mut self, f: F) -> impl Future<Output = ()>
where
Self: Sized,
F: Fn(Self::Item) -> Fut,
Fut: Future<Output = ()>,
{
async move {
while let Some(item) = self.next_async().await {
f(item).await;
}
}
}
fn map_async<B, F, Fut>(self, f: F) -> AsyncMap<Self, F>
where
Self: Sized,
F: Fn(Self::Item) -> Fut,
Fut: Future<Output = B>,
{
AsyncMap { iter: self, f }
}
fn filter_async<F, Fut>(self, f: F) -> AsyncFilter<Self, F>
where
Self: Sized,
F: Fn(Self::Item) -> Fut,
Fut: Future<Output = bool>,
Self::Item: Clone,
{
AsyncFilter { iter: self, f }
}
fn process_results<T, E>(self) -> ProcessResults<Self, T, E>
where
Self: Sized + AsyncIterator<Item = Result<T, E>>,
{
ProcessResults::new(self)
}
}
impl<T> AsyncIterTools for T where T: AsyncIterator + ?Sized {}