title: init different types of same protocol using flatMap
body: <p>I have two <code>structs</code>, which conform to the same <code>protocol</code>. Now I want to parse some JSON which contains both types, and automatically <code>init</code> the concrete type (<code>struct</code>) and put everything in an general array of the protocol's type.</p>
  
  <p>What I got so far:</p>
  
  <pre><code>protocol JSONSerializable {
      init?(json: [String: Any?])
  }
  
  protocol General: JSONSerializable { ... }
  
  struct ConcreteA: General {
      init?(json: [String: Any?]) { ... }
      ...
  }
  
  struct ConcreteB: General {
      init?(json: [String: Any?]) { ... }
      ...
  }
  
  func parse(json: [String: Any?]) -&gt; [General]? {
      // I want this to work generic like:
      return jsonDicts.flatMap { General(json: $0) } // Error: Protocol type ' General' cannot be instantiated
  
      // But the only way I got it working is like this, which is not really generic ;-)
      return jsonDicts.flatMap {
          if let concreteA = ConcreteA(json: $0) {
              return concreteA
          }
  
          if let concreteB = ConcreteB(json: $0) {
              return concreteB
          }
  
          return nil
      }
  }
  </code></pre>
  
  <p>So can you give me any hints or suggestions how I can achieve the desired behaviour?</p>