title: Swift reduce/flatten Dictionary<String,Dictionary> to Dictionary
body: <blockquote>
    <p>Convert this</p>
  </blockquote>
  
  <pre><code>[ 
     "Cat" : ["A" : 1, "B": 2], 
     "Mat" : ["C" : 3, "D": 4]
  ]
  </code></pre>
  
  <blockquote>
    <p>Into</p>
  </blockquote>
  
  <pre><code>[
      "A" : 1, 
      "B" : 2,
      "C" : 3,
      "D" : 4
  ]
  </code></pre>
  
  <p>Without using a loop. In other terms using functions like reduce, flatmap.</p>
  
  <p>The <code>source</code> can be of <strong>type</strong> <code>Dictionary&lt;String,Dictionary&lt;String,String&gt;&gt;</code></p>
  
  <hr>
  
  <p>So far I've managed to reduce the Dictionary to an array of Dictionary</p>
  
  <pre><code>let flatten = source.flatMap({ (k,v) -&gt; [String: String]? in
                              return v
                          })
  
  // flatten = [["A" : 1, "B": 2], ["C" : 3, "D": 4]]]
  </code></pre>