use crate::number::Number; use std::cmp; use std::iter::{Zip, Take}; pub struct Iter { index: usize, data: Vec, degree: usize } impl Iter { pub fn new(data: Vec, degree: usize) -> Iter { Iter { index: 0, data, degree } } pub fn zip(self, other: Self) -> Zip, Take> { let deg = cmp::max(self.degree, other.degree) + 1; let a = self.take(deg); let b = other.take(deg); a.zip(b) } } impl Iterator for Iter { type Item = Number; fn next(&mut self) -> Option { self.index += 1; if self.index <= self.data.len() { Some(self.data[self.index - 1]) } else { Some(0.0) } } }