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

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.

主站蜘蛛池模板: 怀宁县| 元谋县| 炉霍县| 鄄城县| 天津市| 清新县| 鹿泉市| 会同县| 中卫市| 五大连池市| 朝阳区| 炎陵县| 昭觉县| 岚皋县| 灵丘县| 库伦旗| 灯塔市| 安达市| 九台市| 广宗县| 旬阳县| 六安市| 陆川县| 东台市| 东台市| 五台县| 吴桥县| 深水埗区| 会理县| 海宁市| 隆德县| 个旧市| 梁山县| 讷河市| 民丰县| 大余县| 灵川县| 定远县| 瓮安县| 汤阴县| 洛扎县|