我正在使用group_by
一个Observable
但是对于每个新创建的组,我想捕捉导致该组创建使用的元素(使用新键)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)
我希望看到以下两个都被打印出来,但我每次只看到一个。
(<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
在奇怪的情况下,我还看到 snap 元素为 2:
(<rx.linq.groupedobservable.GroupedObservable object at 0x0313EB10>, 2)
任何想法出了什么问题?