Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GroupBy with concatMap duplicates items #1214

@hegelwin

Description

@hegelwin

Hi there!
I need to use groupBy with concatMap to ensure sequentally groups processing.

The following code loses or duplicates items while processing:

  val count = 10
  val items = Vector(1, 2, 3)

  Observable.repeat(items: _*)
    .take(count * items.size)
    .groupBy(identity)
    .concatMap(_.dump("O").take(10).sum)
    .sumL
    .map { result =>
      val expected = List(1, 2, 3).map(_ * count).sum
      println(s"expected '$expected', result '$result', pass '${expected == result}'")
    }
    .runToFuture

Output:

0: O --> 1
1: O --> 1
2: O --> 1
3: O --> 1
4: O --> 1
5: O --> 1
6: O --> 1
7: O --> 1
8: O --> 1
9: O --> 1
11: O stopped
0: O --> 2
1: O --> 2
2: O --> 2
3: O --> 2
4: O --> 2
5: O --> 2
6: O --> 2
7: O --> 2
8: O --> 2
9: O --> 2
11: O stopped
0: O --> 3
1: O --> 3
2: O --> 3
3: O --> 3
4: O --> 3
5: O --> 3
6: O --> 3
7: O --> 3
8: O --> 3
9: O --> 3
11: O stopped
0: O --> 1
1: O completed
expected '60', result '61', pass 'false'

Why is this happening and how can I get it to work correctly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions