# Join named tuples

**URL:** <https://community.seqera.io/t/join-named-tuples/1367>\
**Category:** Ask for help\
**Created:** [November 4, 2024, 11:10pm UTC](https://community.seqera.io/t/join-named-tuples/1367 "2024-11-04T23:10:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dquintanatorres](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/dquintanatorres/32/1149_2.png) [@dquintanatorres](https://community.seqera.io/u/dquintanatorres)\
**Post date:** [November 4, 2024, 11:10pm UTC](https://community.seqera.io/t/join-named-tuples/1367/1 "2024-11-04T23:10:01Z")

</div>

Hi! I’m trying to perform a join operation on named tuples with key-value pairs, where only the `id` key is supposed to be the join key. However, the whole tuple is being treated as the join key. The following code results in the error below:

```auto
workflow {    

    ch1 = Channel.of( [id: "a", foo: 1], [id: "b", foo: 2] )
    ch2 = Channel.of( [id: "b", bar: 4], [id: "a", bar: 3] )

    ch1
        .join(ch2, by: 0, failOnDuplicate: true, failOnMismatch: true)
        .view()

}
/*
Join mismatch for the following entries: 
- key=[id:a, foo:1] values= 
- key=[id:a, bar:3] values= 
- key=[id:b, foo:2] values= 
- key=[id:b, bar:4] values=
*/

```

Removing the keys (`[id: "a", foo: 1]` \> `["a", 1]`) seems to do the trick, but I was wondering if there is a way to join named tuples directly without stripping the names and then reconstructing after the join the original key-value pairs.

Thanks!

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [November 5, 2024, 2:39am UTC](https://community.seqera.io/t/join-named-tuples/1367/2 "2024-11-05T02:39:46Z")

</div>

See the snippet below for a solution:

```auto
workflow {
    ch1 = Channel.of( [id: "a", foo: 1], [id: "b", foo: 2] )
    ch2 = Channel.of( [id: "b", bar: 4], [id: "a", bar: 3] )

    ch1.map { tuple(it.id, it) }
       .join( ch2.map { tuple(it.id, it) } )
       .map { id, v1, v2 -> v1 + v2 }
       .view()
}

```

Output

 ![Captura de Tela 2024-11-04 às 23.40.02](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/2X/1/1be83d518a78064e93b84eb33aec9126f79c2ac1.png)

---

<div class="post-metadata">

**Author:** ![dquintanatorres](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/dquintanatorres/32/1149_2.png) [@dquintanatorres](https://community.seqera.io/u/dquintanatorres)\
**Post date:** [November 5, 2024, 3:04pm UTC](https://community.seqera.io/t/join-named-tuples/1367/3 "2024-11-05T15:04:35Z")

</div>

Hi Marcel, thanks for the help! This definitely looks much cleaner than the workaround I had in mind.

While we’re on the topic, do you think it would be useful for Nextflow to support joins between associative arrays or dictionaries (I have mistakenly referred to these as named tuples above) using a user-defined key as the join key? Are there any potential drawbacks to this approach that I could be missing?

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [November 5, 2024, 8:49pm UTC](https://community.seqera.io/t/join-named-tuples/1367/4 "2024-11-05T20:49:43Z")

</div>

> Do you think it would be useful for Nextflow to support joins between associative arrays or dictionaries (I have mistakenly referred to these as named tuples above) using a user-defined key as the join key?

I think so, yes. I don’t really see any drawback and I think it would be a nice addition to the operators toolbox.

---

<div class="post-metadata">

**Author:** ![dquintanatorres](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/dquintanatorres/32/1149_2.png) [@dquintanatorres](https://community.seqera.io/u/dquintanatorres)\
**Post date:** [November 6, 2024, 7:17pm UTC](https://community.seqera.io/t/join-named-tuples/1367/5 "2024-11-06T19:17:01Z")

</div>

Cool! I’ll open a feature request then.

Thank you again!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [November 13, 2024, 7:17pm UTC](https://community.seqera.io/t/join-named-tuples/1367/6 "2024-11-13T19:17:26Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
