- RxPY Tutorial
- RxPY - Home
- RxPY - Overview
- RxPY - Environment Setup
- RxPY - Latest Release Updates
- RxPY - Working with Observables
- RxPY- Operators
- RxPY - Working With Subject
- RxPY - Concurrency Using Scheduler
- RxPY - Examples
- RxPY Useful Resources
- RxPY - Quick Guide
- RxPY - Useful Resources
- RxPY - Discussion
RxPY - Combining Operators
combine_latest
This operator will create a tuple, for the observable given as input.
Syntax
combine_latest(observable1,observable2,.....)
Parameters
Observable: An observable.
Return value
It returns an observable with the values from the source observable converted to a tuple.
Example
from rx import of, operators as op from datetime import date test = of(1,2,3,4,5,6) test2 = of(11,12,13,14,15,16) test3 = of(111,112,113,114,115,116) sub1 = test.pipe( op.combine_latest(test2, test3) ) sub1.subscribe(lambda x: print("The value is {0}".format(x)))
Output
E:\pyrx>python testrx.py The value is (6, 16, 111) The value is (6, 16, 112) The value is (6, 16, 113) The value is (6, 16, 114) The value is (6, 16, 115) The value is (6, 16, 116)
merge
This operator will merge given observables.
Syntax
merge(observable)
Parameters
Observable: an observable.
Return value
It will return an observable with one sequence from the given observables.
Example
from rx import of, operators as op from datetime import date test = of(1,2,3,4,5,6) test2 = of(11,12,13,14,15,16) sub1 = test.pipe( op.merge(test2) ) sub1.subscribe(lambda x: print("The value is {0}".format(x)))
Output
E:\pyrx>python testrx.py The value is 1 The value is 2 The value is 3 The value is 4 The value is 5 The value is 6 The value is 11 The value is 12 The value is 13 The value is 14 The value is 15 The value is 16
start_with
This operator will take in the given values, and add at the start of the source observable return back the full sequence.
Syntax
start_with(values)
Parameters
values: The values you want to prefix at the start.
Return value
It returns an observable with given values prefixed at the start followed by the values from the source observable.
Example
from rx import of, operators as op from datetime import date test = of(1,2,3,4,5,6) sub1 = test.pipe( op.start_with(-2,-1,0) ) sub1.subscribe(lambda x: print("The value is {0}".format(x)))xExample
Output
E:\pyrx>python testrx.py The value is -2 The value is -1 The value is 0 The value is 1 The value is 2 The value is 3 The value is 4 The value is 5 The value is 6
zip
This operator returns an observable with values in a tuple form, which is formed by taking the first value of the given observable and so on.
Syntax
zip(observable1, observable2...)
Parameters
Observable: an observable
Return value
It returns an observable with values in tuple format.
Example
from rx import of, operators as op from datetime import date test = of(1,2,3,4,5,6) test1 = of(4,8,12,16,20) test2 = of(5,10,15,20,25) sub1 = test.pipe( op.zip(test1, test2) ) sub1.subscribe(lambda x: print("The value is {0}".format(x)))
Output
E:\pyrx>python testrx.py The value is (1, 4, 5) The value is (2, 8, 10) The value is (3, 12, 15) The value is (4, 16, 20) The value is (5, 20, 25)