title: How do I gather ordered outputs of a Nextflow process?
body: <p>I want to gather results from a Nextflow process in the same order in which they were input.  </p>
  
  <p>I know that I could simply pass the values from all the channels through all the processes.  This would ensure that pairs get passed to all processes together.  However, that solution doesn't work well when you start adding multiple processes because it destroys the ability of those process to run in parallel.  For example, in the example code provided if you were to add a add_twenty process and then gather the outputs from both add_ten, add_twenty and vals2.  </p>
  
  <p>Another possible solution I have played with was to add a key to each value in the original channels which essentially turns the original channels into a dictionary (i.e. hash).  But I couldn't get that to work.  I can provide an example if necessary.  </p>
  
  <p>I created a toy example where I create two channels, send one to a process, and then send the processed output and one of the original channels to a new process.  </p>
  
  <pre><code>vals1 = Channel.from(1,2,3,4,5)
  vals2 = Channel.from(1,2,3,4,5)
  
  
  process add_ten {
      input:
      val(vals1)
  
      output:
      val(new_int) into new_vals1
  
      exec:
      new_int = vals1 + 10
  }
  
  process pair {
      echo true
  
      input:
      val(new_vals1)
      val(vals2)
  
      script:
      """
      echo "${new_vals1}, ${vals2}"
      """
  }
  </code></pre>
  
  <p>What I was hoping to see was something like this where the ones digits match:</p>
  
  <pre><code>11, 1
  12, 2
  13, 3
  14, 4
  15, 5
  </code></pre>
  
  <p>Even if those lines were jumbled it would be ok as long as the pairs persist.  For example,</p>
  
  <pre><code>14, 4
  11, 1
  13, 3
  15, 5
  12, 2
  </code></pre>
  
  <p>However, what I see is this:</p>
  
  <pre><code>15, 1
  13, 2
  11, 3
  12, 4
  14, 5
  </code></pre>