Skip to content

with_latest_from producing inconsistent results #96

@mchen402

Description

@mchen402

Hi Dag,

I'm using group_by on an Observable but for each newly created group, I want to snap the element (with the new key) that caused the group to be created using with_latest_from:

>>> from __future__ import print_function
>>> from rx import Observable

>>> # sequence 1, 2, 3, ... every half a second
>>> observable=Observable.interval(500).map(lambda x: x + 1)

>>> # groups into numbers that are divisible by 3 (True) and those that are not (False)
>>> grouped = observable.group_by(lambda x: bool(x%3))

>>> # groups paired with the first element that kicked off the group
>>> grouped.with_latest_from(observable, lambda group, element: (group, element)).subscribe(print)

I'm expecting to see both of the below to be printed, but am only seeing either one each time.

(<rx.linq.groupedobservable.GroupedObservable object at 0xabc>, 1)  # 1 is the element that created group with key=False
(<rx.linq.groupedobservable.GroupedObservable object at 0xdef>, 3)  # 3 is the element that created group with key=True

On the odd occasion I also see the snapped element as 2:

(<rx.linq.groupedobservable.GroupedObservable object at 0x0313EB10>, 2)

Any ideas what is going wrong? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions