From 1891436bf1d6b18f1dded15ae693f90f8a6ab975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 11 Jan 2021 19:44:07 -0300 Subject: Move zip implementation from poly to poly/iter Zip seems more appropriate on an iterator. --- src/poly/iter.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/poly') diff --git a/src/poly/iter.rs b/src/poly/iter.rs index 26c5989..abc7462 100644 --- a/src/poly/iter.rs +++ b/src/poly/iter.rs @@ -1,13 +1,23 @@ use crate::number::Number; +use std::cmp; +use std::iter::{Zip, Take}; pub struct Iter { index: usize, - data: Vec + data: Vec, + degree: usize } impl Iter { - pub fn new(data: Vec) -> Iter { - Iter { index: 0, data } + 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) } } -- cgit v1.2.3