1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
pub trait MutFP { type Scalar; fn mut_map<F>(&mut self, f: F) where F: Fn(Self::Scalar) -> Self::Scalar; fn mut_zip_with<F>(&mut self, f: F, other: &Self) where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar; } impl MutFP for Vec<f64> { type Scalar = f64; fn mut_map<F>(&mut self, f: F) where F: Fn(Self::Scalar) -> Self::Scalar, { for i in 0..self.len() { self[i] = f(self[i]); } } fn mut_zip_with<F>(&mut self, f: F, other: &Self) where F: Fn(Self::Scalar, Self::Scalar) -> Self::Scalar, { for i in 0..self.len() { self[i] = f(self[i], other[i]); } } }