[RxJS] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLatestFrom, another AND-style combination operator, and how it works essentially as map() operator, with some combination properties.
var foo = Rx.Observable.interval(400)
.zip(Rx.Observable.of('h', 'e', 'l', 'l', 'o'), (__, x) => x);
var bar = Rx.Observable.interval(300)
.zip(Rx.Observable.of(0,1,1,0,0,1,0,0,1), (__ ,x) => x); /*
----h----e----l----l----o| (foo)
--0--1--1--0--0--1--0--0--1| (bar)
withLatestFrom((c,n) => n === 1 ? c.toUpperCase() : c.toLowerCase())
----h----E----l----L----o|
*/ var combined = foo.withLatestFrom(bar, (c,n) => n === 1 ? c.toUpperCase() : c.toLowerCase()); combined.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next h"
"next E"
"next l"
"next l"
"next O"
"done"
*/
The foo is the main stream, when foo emit each time, it will take the latest value from bar, if the value from bar is 1, then convert foo to upcase string, otherwise lower case string.
[RxJS] Combination operator: withLatestFrom的更多相关文章
- [RxJS] Combination operator: combineLatest
While merge is an OR-style combination operator, combineLatest is an AND-style combination operator. ...
- [RxJS] Combination operator: zip
CombineLatest and withLatestFrom are both AND-style combination operators. In this lesson, we will l ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- [RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be ...
- rxjs自定义operator
rxjs自定义operator
- [RxJS] Utility operator: do
We just saw map which is a transformation operator. There are a couple of categories of operators, s ...
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- [RxJS] Connection operator: multicast and connect
We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
随机推荐
- app上传 需要的icon
如果提交的ipa包中,未包含必要的Icon就会收到类似的通知,为什么偏偏是Icon-76呢? 因为我们开发的游戏,默认是支持iphone以及ipad的,根据官方提供的参考 Icon-76.png是必须 ...
- Java传递程序员变量
解决方案虽然简单,不过若是想不起来就麻烦啦,好方法往往简单. 1.如何在一个java文件叫A里用另一个java文件叫B的方法叫method()? ...
- 【HTTP】全面比较HTTP GET与POST方法
全面比较HTTP GET与POST方法 1. 基本信息比较 属性 GET方法 POST方法 历史: 通常使用GET方法发送的数据作为URL的一部分将会被浏览器保存起来 使用POST方法提交 ...
- 如何对 Android 库进行依赖管理?
Android 开发人员为项目选择库的时候,考虑的因素不仅仅是功能.可用性.性能.文档丰富度和技术支持情况.他们还关心库的大小,以及要添加的方法数量.因为项目越大,依赖也越多,要把应用的方法数量控制在 ...
- JVM相关参数配置和问题诊断<转>
原文连接:http://blog.csdn.net/chjttony/article/details/6240457 1.Websphere JVM相关问题诊断: 由JVM引起的Websphere问题 ...
- WebSocket能干啥
------这东西到底有什么用途,仔细看了说明,还是不明所以.楼上几位能不能介绍一下实际使用的场景?? 1.可以实现 服务器端(delphi&lazarus@win)<->手机端 ...
- log4j_slf4j log4j.properties
hibernate 使用的日志是slf4j,而 slf4j又有各种实现策略. 使用log4j 就是其中一种方式. 需要的jar 包: log4j-1.2.16.jar slf4j-api-1.6.1. ...
- Microsoft Internet Explorer 内存破坏漏洞(CVE-2013-3193)(MS13-059)
漏洞版本: Microsoft Internet Explorer 6 - 10 漏洞描述: BUGTRAQ ID: 61678 CVE(CAN) ID: CVE-2013-3193 Windows ...
- 支付宝APP支付Java回调具体步骤
/** * 支付宝异步请求通知 * * @param request * @return */@RequestMapping(value = "async", method = R ...
- XenServer的某台机器一直pending住怎么办
XenServer某台VM在操作后,图标一直显示成黄色,无法完成操作,成假死的状态.可以用下面命令强制终止VM: 1.在你假死的机器获得UUID 2.在XenServer的控制台输入如下命令获得ID ...