[RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be alternatively called "vertical combination operators", because of how they work in a marble diagram. Next, we will learn about scan(), which is an important "horizontal combination operator".
var click$ = Rx.Observable.fromEvent(document.querySelector("#btn"), 'click'); /* ----ev-----ev---ev----ev----ev----..
mapTo(1)
----1 -----1 ---1 ----1 ----1-----..
scan( (acc, curr) => acc + curr, 0)
----1------2----3-----4-----5-----.. */ var clicks$ = click$
.mapTo(1)
.scan( (acc, curr) => {
return acc + curr
}, 0); var sub = clicks$.subscribe(
(x) => console.debug("Total Clicks: " + x),
(err) => console.error(err),
() => console.info("DONE")
)
var foo$ = Rx.Observable.of('h', 'e', 'l', 'l', 'o')
.zip(Rx.Observable.interval(500), (c, t) => c); var bar$ = foo$.scan( (acc, curr) => {
return acc + curr;
}, ''); /* -----h-----e-----l-----l------o| (foo)
scan( (acc, curr) => acc + curr, '')
-----h-----(he)--(hel)-(hell)-(hello|) (bar) */ var sub = bar$.subscribe(
(x) => console.debug(x),
(err) => console.error(err),
() => console.info("DONE")
);
/** "h"
"he"
"hel"
"hell"
"hello"
"DONE"
*/
[RxJS] Transformation operator: scan的更多相关文章
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- [RxJS] Transformation operator: map and mapTo
We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't nee ...
- [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] 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] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...
随机推荐
- 【算法】一般冒泡排序 O(n^2) 稳定的 C语言
冒泡排序 一.算法描述 假设序列中有N个元素: 第一趟选取第一个元素作为关键字,从左至右比较,若遇到比它小的则放到它左边(也即两数进行交换),若遇到比它大的,则改为选取该元素作为关键字完成后续的比较, ...
- require.js 入门学习-备
一.为什么要用require.js? 最早的时候,所有Javascript代码都写在一个文件里面,只要加载这一个文件就够了.后来,代码越来越多,一个文件不够了,必须分成多个文件,依次加载.下面的网页代 ...
- bzoj 1031: [JSOI2007]字符加密Cipher 後綴數組模板題
1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3157 Solved: 1233[Submit ...
- SAP Crystal Dashboard Design 2011 win7 x64 安装
suggest: unZip the setup package to C:\dashboard\ (make sure that the path cannot contain non-unico ...
- UIWebView 自定义网页中的alert和confirm提示框风格
.h #import <UIKit/UIKit.h> @interface UIWebView (JavaScriptAlert) -(void)webView:(UIWebView *) ...
- 李洪强漫谈iOS开发[C语言-033]-三元运算符的应用
- struts2-core-2.1.6.jar!/struts-default.xml无法加载的问题
找到合适且匹配的jar包,更改完jar包后要去.metadata---.me_tcat---webapps---项目名----WEB-INF--lib下将多余的jar包去掉,否则还运行时还存在替换掉的 ...
- windows驱动开发推荐书籍
[作者] 猪头三 个人网站 :http://www.x86asm.com/ [序言] 很多人都对驱动开发有兴趣,但往往找不到正确的学习方式.当然这跟驱动开发的本土化资料少有关系.大多学的驱动开发资料都 ...
- Spring MVC 解读——<mvc:annotation-driven/>(转)
转自:http://my.oschina.net/HeliosFly/blog/205343 Spring MVC 解读——<mvc:annotation-driven/> 一.Annot ...
- Android 中LocalBroadcastManager的使用方式
Android 中LocalBroadcastManager的使用方式 在android-support-v4.jar中引入了LocalBroadcastManager,称为局部通知管理器,这种通知的 ...