title: How to use swift flatMap to filter out optionals from an array
body: <p>I'm a little confused around flatMap (added to Swift 1.2)</p>
  
  <p>Say I have an array of some optional type e.g. </p>
  
  <pre><code>let possibles:[Int?] = [nil, 1, 2, 3, nil, nil, 4, 5]
  </code></pre>
  
  <p>In Swift 1.1 I'd do a filter followed by a map like this:</p>
  
  <pre><code>let filtermap = possibles.filter({ return $0 != nil }).map({ return $0! })
  // filtermap = [1, 2, 3, 4, 5]
  </code></pre>
  
  <p>I've been trying to do this using flatMap a couple ways:</p>
  
  <pre><code>var flatmap1 = possibles.flatMap({
      return $0 == nil ? [] : [$0!]
  })
  </code></pre>
  
  <p>and </p>
  
  <pre><code>var flatmap2:[Int] = possibles.flatMap({
      if let exercise = $0 { return [exercise] }
      return []
  })
  </code></pre>
  
  <p>I prefer the last approach (because I don't have to do a forced unwrap <code>$0!</code>... I'm terrified for these and avoid them at all costs) except that I need to specify the Array type.</p>
  
  <p>Is there an alternative away that figures out the type by context, but doesn't have the forced unwrap?</p>