Skip to content

Possible to group by different size for each sample? #5512

Answered by bentsherman
lishengting asked this question in Q&A
Discussion options

You must be logged in to vote

You have to use a groupKey to preserve the group size with each element:

Channel.of(
        [ 1, ['A', 'B', 'C'] ],
        [ 2, ['C', 'A'] ],
        [ 3, ['B', 'D', 'E', 'A'] ]
    )
    .map { key, values -> [ groupKey(key, values.size()), values ] }
    .transpose()
    // process the scattered elements ...
    .groupTuple()
    .map { key, values -> [ key.getGroupTarget(), values ] }
    .view()

groupTuple will recognize the groupKey and use it to emit the groups as soon as they are collected. It's also good to unwrap that groupKey afterward so that it doesn't cause any quirks down the line.

See also: groupTuple

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@lishengting
Comment options

Answer selected by lishengting
Comment options

You must be logged in to vote
2 replies
@bentsherman
Comment options

@xiaojie-ZENG
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants