title: Closures to flat nested objects?
body: <p>I'm starting to learn about closures and want to implement them in a project I'm working on and I'd like some help.</p>
  
  <p>I have a class defined as follows: </p>
  
  <pre><code>class MyObject {
  var name: String?
  var type: String?
  var subObjects: [MyObject]?
  }
  </code></pre>
  
  <p>And I want to use closures or higher oder functions (something like <code>flatMap</code> comes to mind) to flatten an <code>[MyObject]</code> and joining all <code>MyObject</code> and <code>subOjects</code> into one array.</p>
  
  <p>I've tried using <code>[MyObject].flatMap()</code> but this operation doesn't return the nested subObjects.</p>