title: yield from a list of generators created from an array
body: <p>I've got this recursive generator</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var obj = [1,2,3,[4,5,[6,7,8],9],10]
  
  function *flat(x) {
      if (Array.isArray(x))
          for (let y of x)
              yield *flat(y)
      else
          yield 'foo' + x;
  
  }
  
  console.log([...flat(obj)])</code></pre>
  </div>
  </div>
  </p>
  
  <p>It works fine, but I don't like the <code>for</code> part. Is there a way to write it functionally? I tried</p>
  
  <pre><code>if (Array.isArray(x))
     yield *x.map(flat)
  </code></pre>
  
  <p>which didn't work.</p>
  
  <p>Is there a way to write the above function without <code>for</code> loops?</p>