1#[macro_export]
5macro_rules! impl_series_into_iter {
6 ($primitive:ty) => {
8 impl IntoIterator for Series<$primitive> {
9 type Item = $primitive;
10 type IntoIter = IntoIter<$primitive>;
11
12 fn into_iter(self) -> Self::IntoIter {
13 self.values.into_iter()
14 }
15 }
16 };
17}
18
19#[macro_export]
22macro_rules! impl_series_by_series_op_inplace {
23
24 ($operation:ident, $func_name:ident, $op:tt) => {
26 impl<T> $operation<Series<T>> for Series<T>
27 where T: BlackJackData + $operation
28 {
29 fn $func_name(&mut self, other: Series<T>) {
30 let _ = self.values
31 .iter_mut()
32 .zip(other.values.into_iter())
33 .map(|(v, o)| *v $op o)
34 .collect::<Vec<()>>();
35 }
36 }
37 }
38}
39
40#[macro_export]
43macro_rules! impl_series_by_series_op {
44
45 ($operation:ident, $func_name:ident, $op:tt) => {
47
48 impl<T> $operation for Series<T>
50 where
51 T: $operation<Output=T> + BlackJackData,
52 {
53 type Output = Result<Series<T>, BlackJackError>;
54
55 fn $func_name(self, other: Series<T>) -> Self::Output {
56 if self.len() != other.len() {
57 Err(BlackJackError::ValueError(
58 format!("Source series is of size: {}, and other is of size: {}", &self.len(), &other.len())
59 ))
60 } else {
61 let result = self.values
62 .into_iter()
63 .zip(other.values.into_iter())
64 .map(|(x1, x2)| x1 $op x2)
65 .collect();
66 Ok(Series::from_vec(result))
67 }
68
69
70 }
71 }
72
73 }
74}