use crate::{
lenses::{LensOver, LensView},
Optics, OpticsTrait,
};
#[derive(Clone, Copy)]
pub struct Combination(A, B);
impl OpticsTrait for Combination {}
impl std::ops::Add> for Optics
where
A: OpticsTrait,
B: OpticsTrait,
{
type Output = Optics, Optics>>;
fn add(self, rhs: Optics) -> Self::Output {
Optics(Combination(self, rhs))
}
}
impl LensView for Combination
where
A: LensView,
B: LensView,
{
type Field = B::Field;
fn view(&self, thing: T) -> Self::Field {
B::view(&self.1, A::view(&self.0, thing))
}
}
impl LensOver for Combination
where
A: LensOver,
B: LensOver,
{
fn over(&self, thing: T, f: F) -> T
where
F: FnOnce(Self::Field) -> Self::Field,
{
A::over(&self.0, thing, |b| B::over(&self.1, b, f))
}
}