SHARE
TWEET

Untitled

a guest Dec 16th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use num::Float;
  2.  
  3. struct MulIter<I>
  4. where
  5.     I: Iterator,
  6. {
  7.     iter: I,
  8.     scalar: I::Item,
  9. }
  10.  
  11. impl<I> MulIter<I>
  12. where
  13.     I: Iterator,
  14.     I::Item: Float,
  15. {
  16.     pub fn new(iter: I, scalar: I::Item) -> MulIter<I> {
  17.         MulIter {
  18.             iter,
  19.             scalar,
  20.         }
  21.     }
  22. }
  23.  
  24. impl<I> Iterator for MulIter<I>
  25. where
  26.     I: Iterator,
  27.     I::Item: Float,
  28. {
  29.     type Item = I::Item;
  30.    
  31.     fn next(&mut self) -> Option<Self::Item> {
  32.         match self.iter.next() {
  33.             Some(value) => Some(value * self.scalar),
  34.             None => None,
  35.         }
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top