How to parse nested tuples in process input?

Hi, I generate a output channel emission from a process like the following:
[ id, [ [R1, id_R1.fastq.gz], [R2, id_R2.fastq.gz] ] ]. How to parse all elements in this emission separately in the input of the next process? I want to get something like this:
input:
tuple id, tuple(r1, r1file), tuple(r2, r2file) #Of course, this doesn’t work, but how to do it correctly?

It’s not possible to do nested tuples in process output.

You should generally use a .map operator on the process output in order to make this kind of output.

There are two options. The first, which is uncommon, is to use env type to capture any string defined as an environment variable.
The output then would be like:

output:
tuple val(meta), env('R1'), path('*_R1.fastq.gz'), env('R2'), path('*_R2.fastq.gz')

The other more common way to use Groovy to form the R1 and R2 strings

tuple val(meta), path('*_R1.fastq.gz'), path('*_R2.fastq.gz')

and then after the process is called

PROCESS.out.fastq
    .map { meta, r1_fq, r2_fq ->
        tuple( meta, tuple( r1_fq.simpleName, r1_fq ), tuple( r2_fq.simpleName, r2_fq) )
    }

Note: In map you can do nested tuple’s