# HG changeset patch # User Tuomo Valkonen # Date 1729519894 18000 # Node ID b4d369698556acf8d0348c00332f405087df7802 # Parent 121cf065e9ede36f4eb71028cac95866406750e3 Sum Apply implementation improvements diff -r 121cf065e9ed -r b4d369698556 src/mapping.rs --- a/src/mapping.rs Sun Oct 20 23:53:43 2024 -0500 +++ b/src/mapping.rs Mon Oct 21 09:11:34 2024 -0500 @@ -118,12 +118,22 @@ } -impl Apply for Sum +impl Apply for Sum where M : Mapping, M::Codomain : std::iter::Sum { type Output = M::Codomain; fn apply(&self, x : Domain) -> Self::Output { + self.components.iter().map(|c| c.apply(&x)).sum() + } +} + +impl<'a, Domain, M> Apply<&'a Domain> for Sum +where M : Mapping, + M::Codomain : std::iter::Sum { + type Output = M::Codomain; + + fn apply(&self, x : &'a Domain) -> Self::Output { self.components.iter().map(|c| c.apply(x)).sum() } }