use crate::AT;
mod internal;
use internal::OfView;
pub trait Of<Index> where
Index: Clone
{
type View: ?Sized;
fn each_of<F>(&mut self, i: Index, f: F) -> bool where
F: FnMut(&mut Self::View) -> bool;
}
impl<'a, I, T: 'a> Of<()> for I where
I: Iterator<Item=&'a mut T>
{
type View = T;
fn each_of<F>(&mut self, _: (), mut f: F) -> bool where
F: FnMut(&mut Self::View) -> bool
{
for x in self {
if !f(x) { break }
}
true
}
}
pub trait Each: Sized {
type View: ?Sized;
fn each<F>(self, f: F) -> bool where
F: FnMut(&mut Self::View) -> bool;
fn of<Index>(self, i: Index) -> AT<Self, ((), Index)> where
Self::View: Of<Index>,
Index: Clone
{
AT { cps: self, list: ((), i) }
}
}
impl<CPS: Each, Path> Each for AT<CPS, Path> where
Path: OfView<CPS::View>
{
type View = Path::View;
fn each<F>(self, f: F) -> bool where
F: FnMut(&mut Self::View) -> bool
{
self.list.give_access(self.cps, f)
}
}
impl<T: ?Sized> Each for &mut T {
type View = T;
fn each<F>(self, mut f: F) -> bool where
F: FnMut(&mut T) -> bool
{
f(self)
}
}