- Hands-On Reactive Programming with Python
- Romain Picard
- 296字
- 2021-06-24 18:25:13
The from_ operator
The from_ operator is the operator that was used in the previous example to create an observable from a list. The marble diagram of this operator is shown in the following figure:
The prototype of this operator is the following one:
Observable.from_(iterable, scheduler=None)
The first parameter accepts any iterable object. This includes lists, tuples, dictionaries, and any class that implements the iterator methods __iter__ and next. The second parameter is used to provide a scheduler that will be used to emit the items of the observable. This parameter is present on all creation operators. It is useful when running in an asynchronous environment or an environment with concurrency. We will study schedulers in detail in Chapter 5, Concurrency and Paralellism in RxPY.
The from_ operator creates an observable that emits one item per entry in the iterable. It then completes the observable. Here are some examples of usage which show the items that they return:
Observable.from_(sys.argv) # argv[0], argv[1], argv[2]..., completed
Observable.from_([1, 2, 3, 4]) # 1, 2, 3, 4, completed
Observable.from_({'foo': 'fooz', 'bar': 'barz'}) # 'foo', 'bar', completed
Note that when using a dictionary, the observable contains the keys of the dictionary and not the values. This is the same behavior as a classic Python iteration on a dictionary using a for loop.
- Implementing Cisco UCS Solutions
- Linux內核完全注釋(20周年版·第2版)
- Linux從零開始學(視頻教學版)
- SharePoint 2013 WCM Advanced Cookbook
- 玩到極致 iPhone 4S完全攻略
- 嵌入式操作系統(Linux篇)(微課版)
- Linux網絡內核分析與開發
- Linux內核設計的藝術:圖解Linux操作系統架構設計與實現原理
- OpenSolaris設備驅動原理與開發
- Cassandra 3.x High Availability(Second Edition)
- Windows 10從新手到高手
- Heroku Cloud Application Development
- Linux網絡操作系統項目教程(RHEL 7.4/CentOS 7.4)(第3版)(微課版)
- bash shell腳本編程經典實例(第2版)
- Learn Quantum Computing with Python and IBM Quantum Experience