Reduce code duplication by using a macro
This commit is contained in:
parent
fabe36f6b2
commit
9313307ae9
@ -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>
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user