RxPY - 合併運算子



combine_latest

此運算子將為作為輸入提供的可觀察物件建立一個元組。

語法

combine_latest(observable1,observable2,.....)

引數

Observable:可觀察物件。

返回值

它返回值,其中源可觀察物件中的值已轉換為元組。

示例

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)))

輸出

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

此運算子將合併給定的可觀察物件。

語法

merge(observable)

引數

Observable:可觀察物件。

返回值

它將返回值,其中來自給定的可觀察物件的一個序列。

示例

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)))

輸出

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

此運算子將採用給定的值,並將其新增到源可觀察物件返回的完整序列的開頭。

語法

start_with(values)

引數

values:您希望在開頭新增的字首值。

返回值

它返回值,其中給定的值以開頭字首形式新增,後面緊跟源可觀察物件中的值。

示例

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

輸出

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

此運算子返回值,其中值為元組形式,該形式透過獲取給定可觀察物件的第一個值等來形成。

語法

zip(observable1, observable2...)

引數

Observable:可觀察物件

返回值

它返回值,其中值為元組格式。

示例

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)))

輸出

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)
廣告
© . All rights reserved.