title: Merge results from multiple queries in Gremlin
body: <p>Let's say I want to get a few vertices from my database:</p>
  
  <pre><code>g.V(1, 2, 3)
  </code></pre>
  
  <p>And then I have another set of vertices:</p>
  
  <pre><code>g.V(4, 5, 6)
  </code></pre>
  
  <p>Imagine it's not just <code>g.V()</code>, but some more complicated traversal to get my vertices. But the traversal must start with <code>V()</code>, because I wanna pick from all of my nodes.</p>
  
  <p>Let's also assume I wanna do this multiple times. So I might want to merge 7 different result sets. <strong>Each one can have completely different way to get its results.</strong></p>
  
  <hr>
  
  <p>Now I want to merge these two results into one result set. My first thought was this:</p>
  
  <pre><code>g.V(1, 2, 3).fold().as('x').V(4, 5, 6).fold().as('x').select(all, 'x').unfold()
  </code></pre>
  
  <p>But this doesn't work. The second call to <code>fold</code> will clear out my "local variables", because it's a barrier step.</p>
  
  <p>My current attempt is this:</p>
  
  <pre><code>g.V(1, 2, 3).fold().union(identity(), V(4, 5, 6).fold()).unfold()
  </code></pre>
  
  <p>This works, but looks a bit too complicated. If I wanna repeat it 7 times, it'll make for a very complex query.</p>
  
  <p><strong>Is there a better way to accomplish simple merging of results from two different queries?</strong></p>