- Hands-On Reactive Programming with Python
- Romain Picard
- 199字
- 2021-06-24 18:25:21
The merge operator
The merge operator combines several observables into a single observable by merging all items emitted by the source observables in its output observable. The merge operator accepts several observables as input and returns one output observable:
The items emitted by each source observable are interleaved on the output observable. As shown in the Figure 3.7, the output observable completes once all input observables have completed. However, if a source observable completes on error then the output observable immediately completes on error:
The prototype of the merge operator is the following one:
Observable.merge(self, *args)
Observable.merge(*args)
This method can be used as a method of an Observable object, or as a static method of the Observable class. The arguments passed as input can be several observables to merge, or a list containing the observables to merge:
numbers = Observable.from_([1, 2, 3, 4])
strings = Observable.from_(["one", "two", "three", "four"])
print("Merge from object method:")
numbers.merge(strings) \
.subscribe(
on_next=lambda i: print("item: {}".format(i)),
on_error=lambda e: print("error: {}".format(e)),
on_completed=lambda: print("completed")
)
print("Merge from class static method:")
Observable.merge([numbers, strings]) \
.subscribe(
on_next=lambda i: print("item: {}".format(i)),
on_error=lambda e: print("error: {}".format(e)),
on_completed=lambda: print("completed")
)
- Linux內(nèi)核完全注釋(20周年版·第2版)
- Haskell Financial Data Modeling and Predictive Analytics
- 高性能Linux服務(wù)器構(gòu)建實戰(zhàn):運維監(jiān)控、性能調(diào)優(yōu)與集群應(yīng)用
- Windows Server 2012 Hyper-V Cookbook
- Linux集群和自動化運維
- Windows Phone應(yīng)用程序開發(fā)
- 混沌工程:復(fù)雜系統(tǒng)韌性實現(xiàn)之道
- 深入理解eBPF與可觀測性
- 計算機系統(tǒng):基于x86+Linux平臺
- 深入淺出Node.js
- 新編電腦辦公(Windows 10+ Office 2013版)從入門到精通
- 精解Windows 10
- Building Telephony Systems With Asterisk
- 從實踐中學(xué)習(xí)Windows滲透測試
- bash shell腳本編程經(jīng)典實例(第2版)