use super::{m_builtin, m_method, m_order_by, m_select};
use m_builtin::{ConcateIterator, ReverseIterator, SelectIterator, WhereIterator};
use m_order_by::OrderedIterator;
use m_select::{SelectManyIterator, SelectManySingleIterator};
pub trait Enumerable: Iterator {
fn where_by<P>(self, predicate: P) -> WhereIterator<Self, P>
where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
{
m_builtin::where_by(self, predicate)
}
fn select<TResult, F>(self, f: F) -> SelectIterator<Self, F>
where
Self: Sized,
F: FnMut(Self::Item) -> TResult,
{
m_builtin::select(self, f)
}
fn select_many_single<TResult, TCollection, F>(
self,
f: F,
) -> SelectManySingleIterator<Self, TCollection, F>
where
Self: Sized,
TCollection: Enumerable<Item = TResult>,
F: FnMut(Self::Item) -> TCollection,
{
m_select::select_many_single(self, f)
}
fn select_many<TResult, TCollection, TItem, FC, FR>(
self,
fc: FC,
fr: FR,
) -> SelectManyIterator<Self, TCollection, FC, FR>
where
Self: Sized,
Self::Item: Clone,
TCollection: Enumerable<Item = TItem>,
FC: FnMut(Self::Item) -> TCollection,
FR: FnMut(Self::Item, TItem) -> TResult,
{
m_select::select_many(self, fc, fr)
}
fn order_by<TKey, F>(self, f: F) -> OrderedIterator<Self::Item>
where
Self: Sized,
TKey: Ord,
F: Fn(&Self::Item) -> TKey,
{
m_order_by::order_by(self, f, false)
}
fn order_by_descending<TKey, F>(self, f: F) -> OrderedIterator<Self::Item>
where
Self: Sized,
TKey: Ord,
F: Fn(&Self::Item) -> TKey,
{
m_order_by::order_by(self, f, true)
}
fn concate<U>(self, other: U) -> ConcateIterator<Self, U>
where
Self: Sized,
U: Enumerable<Item = Self::Item>,
{
m_builtin::concate(self, other)
}
fn first(self) -> Option<Self::Item>
where
Self: Sized,
{
m_builtin::first(self)
}
fn element_at(self, index: usize) -> Option<Self::Item>
where
Self: Sized,
{
m_builtin::element_at(self, index)
}
fn single(self) -> Option<Self::Item>
where
Self: Sized,
{
m_method::single(self)
}
fn reverse(self) -> ReverseIterator<Self>
where
Self: Sized + DoubleEndedIterator,
{
m_builtin::reverse(self)
}
fn contains(self, value: &Self::Item) -> bool
where
Self: Sized,
Self::Item: Eq,
{
m_method::contains(self, value)
}
fn aggregate<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
m_builtin::aggregate(self, init, f)
}
}
impl<I, T> Enumerable for I where I: Iterator<Item = T> {}