title: How do I perform iterator computations over iterators of Results without collecting to a temporary vector?
body: <p>I'm looking for a way to eliminate the temporary vector allocation in this example:</p>
  
  <pre><code>fn doit&lt;T: Iterator&lt;Item = Result&lt;i32, &amp;'static str&gt;&gt;&gt;(name: &amp;str, iter: T) {
      println!(
          "{}: {:?}",
          name,
          iter.collect::&lt;Result&lt;Vec&lt;_&gt;, _&gt;&gt;()
              .map(|v| v.into_iter().min())
      );
  }
  
  fn main() {
      let without_errors = vec![Ok(1), Ok(2), Ok(3)];
      let with_errors = vec![Ok(1), Err("error"), Ok(2)];
  
      doit("without errors", without_errors.into_iter());
      doit("with errors", with_errors.into_iter());
  }
  </code></pre>
  
  <p>This is a variation of the <em>iterator with error handling</em> theme, except that I don't want to create a collection (so <code>collect()</code> doesn't quite do the job), but I want to perform further operations on the elements being iterated over.</p>
  
  <p>Note that this gives the wrong result because <code>Ok</code> is less than <code>Err</code>:</p>
  
  <pre><code>fn doit&lt;T: Iterator&lt;Item = Result&lt;i32, &amp;'static str&gt;&gt;&gt;(name: &amp;str, iter: T) {
      println!("{}: {:?}", name, iter.min());
  }
  </code></pre>
  
  <p>It would give the right result for <code>max()</code> by accident, but it would not stop iterating on the first error.</p>