官术网_书友最值得收藏!

The map operator

Let's see a real example with the map operator. This operator takes a source observable as input and returns an observable as output. It applies a function to each item of the source observable, and emits the result of this function on the output observable. Hopefully, its marble diagram, shown in the following figure, should make the description much more clear:

Figure 1.10: The map operator

The marble diagram shows an input timeline with three integer items: 1, 12, and 7. The transformation is described with syntax similar to that of the Python lambda. Note that the official ReactiveX documentation uses the JavaScript arrow function notation, because it uses marble diagrams from the JavaScript implementation. In this example, the transformation is a multiplication by 3 of the source item. The output timeline contains also three items, corresponding to the input items values multiplied by 3.

The prototype of this operator is the following one:

Observable.map(self, selector)

The selector parameter is the function that will be executed on all items of the input observable.

主站蜘蛛池模板: 黑河市| 沅陵县| 灌阳县| 辉南县| 凤凰县| 和平县| 浮梁县| 鄂州市| 红原县| 炎陵县| 广河县| 宜章县| 依安县| 瓦房店市| 江门市| 乡宁县| 衡南县| 大港区| 汤阴县| 灌南县| 镇沅| 炉霍县| 洛宁县| 贵德县| 东阳市| 额济纳旗| 赤城县| 南阳市| 临沭县| 乐业县| 滨州市| 漾濞| 灌南县| 漳州市| 内江市| 瓮安县| 遂川县| 古交市| 比如县| 五河县| 河北省|