title: Swift || How to filter kid array by parent array elements?
body: <p>i have two data models as below:</p>
  <pre class="lang-swift prettyprint-override"><code>
  class Card {
      let type: String
      let name: String
      let icon: String
      
      init(
          type: String,
          name: String,
          icon: String
      ) {
          self.type = type
          self.icon = icon
          self.name = name
      }
  }
  
  class Product {
      let type: String? // please watch out here is optional value
      let imageUrl: String
      let content: String
      
      init(
          type: String?,
          imageUrl: String,
          content: String
      ) {
          self.type = type
          self.imageUrl = imageUrl
          self.content = content
      }
  }
  </code></pre>
  <p>And I managed to get the above two entities mapped data with API response, right now I got a new requirement that needs to merge the above two data entities as the following structure. and products be filtered by same <code>type</code> which included in both <code>Card</code> and <code>Product</code></p>
  <pre class="lang-swift prettyprint-override"><code>class MergedData {
      let type: String // same &quot;type&quot; with &quot;Product.type&quot;
      let name: String
      let icon: String
      let products: [Product] // products inserted here should have same &quot;type&quot; 
     
      init(
          type: String,
          name: String,
          icon: String,
          products: [Product]
      ) {
          self.type = type
          self.icon = icon
          self.name = name
          self.products = products
      }
      
  }
  </code></pre>
  <p>lets say we have a <code>DemoViewModel</code> here</p>
  <pre class="lang-swift prettyprint-override"><code>class DemoViewModel {
      
      var cards: [Card]
      var products: [Product]
      var mergedData: [MergedData] = [] 
      
      init(cards: [Card],
           products: [Product]) {
          self.cards = cards  
          self.products = products
      }
      
      func getMergedData() -&gt; [MergedData] {
          // how to write here ?
      }
  }
  </code></pre>
  <p>how to write the content of <code>getMergedData</code> ?</p>