Reduce code duplication by using a macro

This commit is contained in:
Vinzent Steinberg 2017-06-23 16:42:54 +02:00
parent fabe36f6b2
commit 9313307ae9
6 changed files with 13 additions and 55 deletions

View File

@ -138,6 +138,14 @@ macro_rules! concatenate {
}
}
impl_from_iterator!($name);
};
}
/// Implement `FromIterator<f64>` for an iterative estimator.
#[macro_export]
macro_rules! impl_from_iterator {
( $name:ident ) => {
impl ::core::iter::FromIterator<f64> for $name {
fn from_iter<T>(iter: T) -> $name
where T: IntoIterator<Item=f64>

View File

@ -166,14 +166,4 @@ impl core::default::Default for Max {
}
}
impl core::iter::FromIterator<f64> for Max {
fn from_iter<T>(iter: T) -> Max
where T: IntoIterator<Item=f64>
{
let mut a = Max::new();
for i in iter {
a.add(i);
}
a
}
}
impl_from_iterator!(Max);

View File

@ -132,14 +132,4 @@ impl Kurtosis {
}
}
impl core::iter::FromIterator<f64> for Kurtosis {
fn from_iter<T>(iter: T) -> Kurtosis
where T: IntoIterator<Item=f64>
{
let mut a = Kurtosis::new();
for i in iter {
a.add(i);
}
a
}
}
impl_from_iterator!(Kurtosis);

View File

@ -120,14 +120,4 @@ impl core::default::Default for Mean {
}
}
impl core::iter::FromIterator<f64> for Mean {
fn from_iter<T>(iter: T) -> Mean
where T: IntoIterator<Item=f64>
{
let mut a = Mean::new();
for i in iter {
a.add(i);
}
a
}
}
impl_from_iterator!(Mean);

View File

@ -123,14 +123,4 @@ impl Skewness {
}
}
impl core::iter::FromIterator<f64> for Skewness {
fn from_iter<T>(iter: T) -> Skewness
where T: IntoIterator<Item=f64>
{
let mut a = Skewness::new();
for i in iter {
a.add(i);
}
a
}
}
impl_from_iterator!(Skewness);

View File

@ -150,14 +150,4 @@ impl core::default::Default for Variance {
}
}
impl core::iter::FromIterator<f64> for Variance {
fn from_iter<T>(iter: T) -> Variance
where T: IntoIterator<Item=f64>
{
let mut a = Variance::new();
for i in iter {
a.add(i);
}
a
}
}
impl_from_iterator!(Variance);