Created
December 13, 2016 16:01
-
-
Save Pamplemousse/dc77fecfe7fdbe8875f439b847f9dc62 to your computer and use it in GitHub Desktop.
pair_with_previous method for Observable instances in RxPy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rx.core import Observable, AnonymousObservable | |
from rx.internal import extensionmethod | |
@extensionmethod(Observable) | |
def pair_with_previous(self): | |
""" | |
stream = Observable.from_iterable( | |
list(map( | |
lambda x: [1*x, 2*x], | |
range(6))) | |
) | |
stream = stream.pair_with_previous() | |
stream.subscribe(print) | |
""" | |
return self.scan( | |
lambda acc, current: (acc[1], current), | |
(None, None) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment