0

を使用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

奇妙な機会に、スナップされた要素が 2 として表示されることもあります。

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

何がうまくいかないのですか?

4

1 に答える 1