title: How do I parse a string to a list of floats using functional style?
body: <p>I am trying to parse a string into a list of floating-point values in Rust. I would assume there is a clever way to do this using iterators and <code>Option</code>s; however, I cannot get it to ignore the <code>Err</code> values that result from failed parse() calls. The Rust tutorial doesn't seem to cover any examples like this, and the documentation is confusing at best.</p>
  
  <p>How would I go about implementing this using the functional-style vector/list operations? Pointers on better Rust style for my iterative implementation would be appreciated as well!</p>
  
  <p><strong>"Functional"-style</strong></p>
  
  <p>Panics when it encounters an <code>Err</code></p>
  
  <pre><code>input.split(" ").map(|s| s.parse::&lt;f32&gt;().unwrap()).collect::&lt;Vec&lt;_&gt;&gt;()
  </code></pre>
  
  <p><strong>Iterative-style</strong></p>
  
  <p>Ignores non-float values as intended</p>
  
  <pre><code>fn parse_string(input: &amp;str) -&gt; Vec&lt;f32&gt; {
      let mut vals = Vec::new();
      for val in input.split_whitespace() {
          match val.parse() {
              Ok(v) =&gt; vals.push(v),
              Err(_) =&gt; (),
          }
      }
      vals
  }
  
  fn main() {
      let params = parse_string("1 -5.2  3.8 abc");
      for &amp;param in params.iter() {
          println!("{:.2}", param);
      }
  }
  </code></pre>