Groupe tuple with 2 values #5762
Unanswered
wdesaintjean
asked this question in
Q&A
Replies: 1 comment 1 reply
-
It's possible, but it ain't pretty inputs_ch = Channel.of(
tuple('5Y_siGL2_B1', 'group1'),
tuple('5Y_siGL2_B2', 'group1'),
tuple('5Y_siGL2_B3', 'group2'),
tuple('5Y_siDDX5_17_B1', 'group2'),
tuple('5Y_siDDX5_17_B2', 'group3'),
tuple('5Y_siDDX5_17_B3', 'group3')
)
inputs_ch
// generate pairwise combinations
.combine(inputs_ch)
// filter out duplicates
.filter { _vleft, kleft, _vright, kright ->
kleft < kright
}
// rearrange some things
.map { vleft, kleft, vright, kright ->
tuple([vleft, vright].toSet(), [kleft, kright].toSet())
}
// group by pair
.groupTuple(by: 1)
// flatten all the pair sets from map() into one big set
.map { vpairs, key ->
tuple(vpairs.flatten().toSet(), key)
}
// all done
.view() Probably a few different ways to do it, but fundamentally I think you have to (1) generate the pairwise combinations, (2) filter out the duplicates, and (3) group as normal, with some glue logic here and there to make it work |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I need help about en operation on channel:
I have this channel:
and I want them to be grouped by the second item (here group1, group2, group3), but I want a group that contain 2 values of the second item, given by this other channel.
I know I can group them by the first item with
.groupTuple(by: 1)
, but I obtain this channel:The results I want is more like this:
Is it possible with simple operators?
Thank you for your help.
Beta Was this translation helpful? Give feedback.
All reactions