[RxJS] Transformation operator: map and mapTo
We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't need it because it's too specific: it only does simple multiplication on numbers. In this lesson we will see how the map() operator is useful for any calculation on delivered values.
map:
var foo = Rx.Observable.interval(1000); /* foo: ---0---1---2---3--...
map(x => x / 2)
bar: ---0---2---4---6--... */ // map take a function
var bar = foo.map(x => x / 2); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
mapTo:
var foo = Rx.Observable.interval(1000); /* foo: --- 0---1--- 2--- 3--...
mapTo(10)
bar: ---10---10---10---10--... */ // mapTo take a value
var bar = foo.mapTo(10); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
[RxJS] Transformation operator: map and mapTo的更多相关文章
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- [RxJS] Transformation operator: bufferToggle, bufferWhen
bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>) bufferToggle take ...
- [RxJS] Utility operator: do
We just saw map which is a transformation operator. There are a couple of categories of operators, s ...
- rxjs自定义operator
rxjs自定义operator
- [RxJS] Implement the `map` Operator from Scratch in RxJS
While it's great to use the RxJS built-in operators, it's also important to realize you now have the ...
- [RxJS] Use RxJS concatMap to map and concat high order observables
Like switchMap and mergeMap, concatMap is a shortcut for map() followed by a concatAll(). In this le ...
- [RxJS] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...
随机推荐
- JavaScript学习心得(三)
一 变量 var:变量声明 变量名 =:赋值 简单值类型 全局变量:编程的一般规则——应用程序应该只完成必须的最少功能,如果一个变量不是绝对必需,就不该是全局:全局变量对维护性能不利,因为需要一直维护 ...
- CANoe 入门 Step by step系列(三)简单例子的剖析【转】
最好的学习方式是什么?模仿.有人会问,那不是山寨么?但是我认为,那是模仿的初级阶段,当把别人最好的设计已经融化到自己的血液里,变成自己的东西,而灵活运用的时候,才是真正高级阶段.正所谓画虎画皮难画骨. ...
- WPF Window异形窗口演示
我们先通过简单的效果展示,切换展示不同图片: 我们先定义图片资源文件,我们可以在window资源中定义,下面的在app.xaml文件来定义: <Application x:Class=" ...
- C语言学习总结(三) 复杂类型
第五章.复杂数据类型 (数组.字符串.指针.结构体.枚举.共同体) 1.什么是数组? 概念:把具有相同类型的若干变量按有序的形式组织起来,这些按序排列的同类数据元素的集合称为数组: 按数组元素的类型不 ...
- URL encode 与 URL decode 的C语言实现
转载自:http://blog.csdn.net/langeldep/article/details/6264058 本文代码为从PHP代码中修改而来,只保留了2个函数. int php_url_de ...
- eclipse 启动tomcat报Spring错误 Error creating bean with name 'serviceOrderBiz': Injection of autowired dependencies failed
启动tomcat报异常,提示Sring无法创建serviceOrderBiz(第一行红字),继续看是因为有一个自动注入的字段无法注入ModuleInterfaceBiz(第二行红字),检查servic ...
- jquery学会的
1.$("#id") $("xxxxx") (input, body) $(".class") 2. $("#id xxx ...
- [BZOJ - 2631] tree 【LCT】
题目链接:BZOJ - 2631 题目分析 LCT,像线段树区间乘,区间加那样打标记. 这道题我调了一下午. 提交之后TLE了,我一直以为是写错了导致了死循环. 于是一直在排查错误.直到.. 直到我看 ...
- 无插件Vim编程技巧
无插件Vim编程技巧 http://bbs.byr.cn/#!article/buptAUTA/59钻风 2014-03-24 09:43:46 发表于:vim 相信大家看过<简明Vim教程& ...
- python包管理-distutils,setuptools,pip,virtualenv等介绍
python包管理-distutils,setuptools,pip,virtualenv等介绍 对于每个编程语言来说打包和发布开发包往往非常重要,而作为一个编程者能够快速容易的获得并应用这些由第三方 ...