I need to separate a channel with complex list:
The channel contains a nested list like this one: [1,['a','b'],['c','d']],[2,['a','b'],['e','f']]
How to create two new channels so that channel one contains [[1,a,c],[2,a,e]] and channel two - [[1,b,d],[2,b,f]], which basically means separating each original nested list element in two (e.g. [1,[a,b],[c,d]] becomes [1,a,c],[1,b,d]) and then combining by the second inner element ([a,b] in both cases).
So far i have managed to create a very primitive solution:
Channel
.from([1,['a','b'],['c','d']],[2,['a','b'],['e','f']])
.multiMap {
ch_one: tuple (it[0], it[1][0], it[2][0])
ch_two: tuple (it[0], it[1][1], it[2][1])
}
.set { to_mix }
to_mix.ch_one.subscribe {println it}
to_mix.ch_two.subscribe {println it}
Is there a better way to do it?