[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 ...
随机推荐
- Kafka源码分析-序列2 -Producer
在上一篇,我们从使用方式和策略上,对消息队列做了一个宏观描述.从本篇开始,我们将深入到源码内部,仔细分析Kafka到底是如何实现一个分布式消息队列.我们的分析将从Producer端开始. 从Kafka ...
- 使用php发送电子邮件(phpmailer)
在项目开发过程中,经常会用到通过程序发送电子邮件,例如:注册用户通过邮件激活,通过邮件找回密码,发送报表等.这里介绍几种通过PHP发送电子邮件的 方式(1)通过mail()函数发送邮件(2)使用fso ...
- PHP扩展Redis编译安装
PHP扩展Redis编译安装 1.下载PHP官方Redis源码包 wget http://pecl.php.net/get/redis-2.2.4.tgz 注:我用的是Redhat系统,ubunt ...
- Centos7 修改运行级别
systemd使用比sysvinit的运行级别更为自由的target概念作为替代 第三运行级: multi-user.target 第五运行级: graphical.target #前者是符号链接 ...
- WPF ListView的使用及Linq to XML练习
环境:VS2010 控件:ListView 技术:Linq to XML:MVVM 源码:http://files.cnblogs.com/jumahe/Wpf_Customer.rar 布局描述: ...
- 支付宝openssl漏洞肆虐 互联网巨头称目前已修复
支付宝openssl漏洞肆虐 互联网巨头称目前已修复 金山毒霸安全专家李铁军表示,这个漏洞使黑客可以远程读取https服务器的随机64KB内存,“只要这个黑客有耐心多捕获多分析那些64KB的数据,用户 ...
- 【POJ2699】The Maximum Number of Strong Kings(网络流)
Description A tournament can be represented by a complete graph in which each vertex denotes a playe ...
- oracle中有关用户、角色的一些概念。
oracle中的每个用户对应一个单独的方案(schema),方案的名字与用户名一样,方案中包含很多数据对象,表,视图,触发器,存储过程等元素. oracle中管理数据库的角色有sys,system,数 ...
- Ultraedit中使用Astyle格式化代码
方法: 使用UE的自定义工具栏并借助开源工具astyle.exe来完成. 1. 首先下载最新的astyle,因为ue自带的astyle版本太老,不支持空格.中文名等. http://astyle.so ...
- (转载)php获取mysql版本的几种方法小结
(转载)http://www.jb51.net/article/13930.htm 查询当前连接的MYSQL数据库的版本,可以用下面SQL语句来实现 select VERSION(); 当前$res= ...