title: Understanding filter_map in rust
body: <p>I am trying to get <code>ages</code> of all <code>Person</code> who has some second name. I was able to do it using <code>filter</code> and <code>map</code> separately as below, But I am wondering if we can use <code>filter_map</code> in rust.</p>
  <p>But I am unable to figure it out.</p>
  <pre class="lang-rust prettyprint-override"><code>struct Person {
      pub first_name: String,
      pub last_name: Option&lt;String&gt;,
      pub age: i32,
  }
  
  
  fn main() {
      let mut persons: Vec&lt;Person&gt; = Vec::new();
      persons.push(Person {
          first_name: &quot;Asnim&quot;.to_string(),
          last_name: None,
          age: 1,
      });
      persons.push(Person {
          first_name: &quot;Fahim&quot;.to_string(),
          last_name: Some(&quot;Ansari&quot;.to_string()),
          age: 2,
      });
      persons.push(Person {
          first_name: &quot;Shahul&quot;.to_string(),
          last_name: None,
          age: 6,
      });
      persons.push(Person {
          first_name: &quot;Mujeeb&quot;.to_string(),
          last_name: Some(&quot;Rahuman&quot;.to_string()),
          age: 6,
      });
  
      let ages_of_people_with_second_name_using_seperate_filter_map: Vec&lt;i32&gt; = persons
          .iter()
          .filter(|p| p.last_name.is_some())
          .map(|p| p.age)
          .collect();
  
      println!(&quot;{:?}&quot;, ages_of_people_with_second_name)
  }
  </code></pre>