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

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.

主站蜘蛛池模板: 彭水| 西宁市| 乌兰察布市| 湘西| 红原县| 普陀区| 棋牌| 县级市| 东山县| 牟定县| 五寨县| 淄博市| 久治县| 江山市| 雷波县| 丰台区| 绵阳市| 昌吉市| 阿拉善左旗| 涟源市| 和平区| 海淀区| 股票| 根河市| 招远市| 齐齐哈尔市| 清丰县| 连平县| 霞浦县| 黎川县| 东丽区| 贞丰县| 弥勒县| 丹棱县| 江口县| 大渡口区| 丘北县| 扶绥县| 浦城县| 太仆寺旗| 山阴县|