title: Swift "where" Array Extensions
body: <p>As of Swift 2.0 it seems we can get closer to extensions of generic types applicable to predicated situations. </p>
  
  <p>Although we still can't do this:</p>
  
  <pre><code>protocol Idable {
      var id : String { get }
  }
  
  extension Array where T : Idable {
      ...
  }
  </code></pre>
  
  <p>...we can now do this:</p>
  
  <pre><code>extension Array {
      func filterWithId&lt;T where T : Idable&gt;(id : String) -&gt; [T] {
      ...
      }
  }
  </code></pre>
  
  <p>...and Swift grammatically accepts it. However, for the life of me I cannot figure out how to make the compiler happy when I fill in the contents of the example function. Suppose I were to be as explicit as possible:</p>
  
  <pre><code>extension Array {
      func filterWithId&lt;T where T : Idable&gt;(id : String) -&gt; [T] {
          return self.filter { (item : T) -&gt; Bool in
              return item.id == id
          }
      }
  }
  </code></pre>
  
  <p>...the compiler will not accept the closure provided to filter, complaining </p>
  
  <blockquote>
    <p>Cannot invoke 'filter' with an argument list of type '((T) -> Bool)'</p>
  </blockquote>
  
  <p>Similar if item is specified as Idable. Anyone had any luck here?</p>