orx_iterable/transformations/
flattened.rsuse crate::{Collection, CollectionMut, Iterable};
use core::marker::PhantomData;
use orx_self_or::SoM;
pub struct Flattened<I>
where
    I: Iterable,
    I::Item: IntoIterator,
{
    pub(crate) it: I,
}
impl<I> Iterable for Flattened<I>
where
    I: Iterable,
    I::Item: IntoIterator,
{
    type Item = <I::Item as IntoIterator>::Item;
    type Iter = core::iter::Flatten<I::Iter>;
    fn iter(&self) -> Self::Iter {
        self.it.iter().flatten()
    }
}
pub struct FlattenedCol<I, E>
where
    I: Collection,
    I::Item: IntoIterator,
    for<'i> &'i I::Item: IntoIterator<Item = &'i <I::Item as IntoIterator>::Item>,
    E: SoM<I>,
{
    pub(crate) it: E,
    pub(crate) phantom: PhantomData<I>,
}
impl<'a, I, E> Iterable for &'a FlattenedCol<I, E>
where
    I: Collection,
    I::Item: IntoIterator,
    for<'i> &'i I::Item: IntoIterator<Item = &'i <I::Item as IntoIterator>::Item>,
    E: SoM<I>,
{
    type Item = &'a <I::Item as IntoIterator>::Item;
    type Iter = core::iter::Flatten<<I::Iterable<'a> as Iterable>::Iter>;
    fn iter(&self) -> Self::Iter {
        self.it.get_ref().iter().flatten()
    }
}
impl<I, E> Collection for FlattenedCol<I, E>
where
    I: Collection,
    I::Item: IntoIterator,
    for<'i> &'i I::Item: IntoIterator<Item = &'i <I::Item as IntoIterator>::Item>,
    E: SoM<I>,
{
    type Item = <I::Item as IntoIterator>::Item;
    type Iterable<'i>
        = &'i Self
    where
        Self: 'i;
    fn as_iterable(&self) -> Self::Iterable<'_> {
        self
    }
}
impl<I, E> CollectionMut for FlattenedCol<I, E>
where
    I: CollectionMut,
    I::Item: IntoIterator,
    for<'i> &'i I::Item: IntoIterator<Item = &'i <I::Item as IntoIterator>::Item>,
    for<'i> &'i mut I::Item: IntoIterator<Item = &'i mut <I::Item as IntoIterator>::Item>,
    E: SoM<I>,
{
    type IterMut<'i>
        = core::iter::Flatten<I::IterMut<'i>>
    where
        Self: 'i;
    fn iter_mut(&mut self) -> Self::IterMut<'_> {
        self.it.get_mut().iter_mut().flatten()
    }
}