[RxJS] Filtering operators: take, first, skip
There are more operators in the filtering category besides filter(). This lesson will teach how take(), first(), and skip() are simply operators to ignore or pass a certain amount of events from the source Observable.
- var foo = Rx.Observable.interval(100);
- /*
- --0--1--2--3--4--5--6--7-
- take(5)
- --0--1--2--3--4
- */
- var bar = foo.take(5);
- bar.subscribe(
- function (x) { console.log('next ' + x); },
- function (err) { console.log('error ' + err); },
- function () { console.log('done'); },
- );
- /**
- "next 0"
- "next 1"
- "next 2"
- "next 3"
- "next 4"
- "done"
- */
first():
- var foo = Rx.Observable.interval(100);
- /*
- --0--1--2--3--4--5--6--7-
- first()
- --0
- */
- var bar = foo.first();
- bar.subscribe(
- function (x) { console.log('next ' + x); },
- function (err) { console.log('error ' + err); },
- function () { console.log('done'); },
- );
- /**
- "next 0"
- "done"
- */
skip(number): different with take(), it skip the first number of item, and show the rest:
- var foo = Rx.Observable.interval(100);
- /*
- --0--1--2--3--4--5--6--7
- skip(5).take(3)
- -----------------5--6--7
- */
- var bar = foo.skip(5).take(3);
- bar.subscribe(
- function (x) { console.log('next ' + x); },
- function (err) { console.log('error ' + err); },
- function () { console.log('done'); },
- );
- /**
- "next 5"
- "next 6"
- "next 7"
- "done"
- */
[RxJS] Filtering operators: take, first, skip的更多相关文章
- [RxJS] Filtering operators: takeLast, last
Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...
- [RxJS] Filtering operators: distinct and distinctUntilChanged
Operator distinct() and its variants are an important type of Filtering operator. This lessons shows ...
- [RxJS] Filtering operators: skipWhile and skipUntil
After takeUntil() and takeWhile() function, let's have a look on skipWhile() and skilUntil() functio ...
- [RxJS] Filtering operators: throttle and throttleTime
Debounce is known to be a rate-limiting operator, but it's not the only one. This lessons introduces ...
- [RxJS] Filtering operators: takeUntil, takeWhile
take(), takeLast(), first(), last(), those opreators all take number or no param. takeUtil and takeW ...
- [RxJS] Transformation operators: debounce and debounceTime
Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...
- [RxJS] Transformation operators: delay and delayWhen
This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...
- [RxJS] Creation operators: interval and timer
It is quite common to need an Observable that ticks periodically, for instance every second or every ...
- [RxJS] Creation operators: empty, never, throw
This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...
随机推荐
- 更改input【type=file】样式
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- ExecuteNonQuery()返回值
查询某个表中是否有数据的时候,我用了ExecuteNonQuery(),并通过判断值是否大于0来判断数据的存在与否.结果与我所设想的很不一致,调试时才发现,其执行后返回的结果是-1,对此我很是不理解, ...
- Android 网络通信 HTTP
摘要 1. Http GET 方法访问网站 2. Http POST访问网站 3. HttpClient进行Get方式通信 4. HttpClient进行Post方式通信 -------------- ...
- 关于java reflect
反射的基石 Class类 对比提问: Person类代表人,它的实例对象就是张三,李四这样一个个具体的人, Java程序中的各个Java类属于同一类事物,描述这类事物的Java类名就是Class.对比 ...
- User Commands
archive Creates a hadoop archive[v.存档; n.档案文件; 档案室; ]. More information can be found at Hadoop Archi ...
- Sharepoint 问题集锦 - external list (外部列表)
使用Sharepoint开发过程中遇到的问题总结. 错误1: Unable to display this Web Part. To troubleshoot the problem, open th ...
- 《深入剖析Tomcat》阅读(一)
第一章 一个简单的Web服务器 该应用程序仅接受位于指定目录的静态资源的请求,如HTML文件和图像文件.它也可以将传入的HTTP请求字节流显示到控制台上.但是,它并不发送任何头信息到浏览器,如日期或者 ...
- [HDOJ 5183] Negative and Positive (NP) 【Hash】
题目链接:HDOJ - 5183 题目分析 分两种情况,奇数位正偶数位负或者相反. 从1到n枚举,在Hash表中查询 Sum[i] - k ,然后将 Sum[i] 加入 Hash 表中. BestCo ...
- 如何监控 Nginx?
什么是 Nginx? Nginx("engine-x")是一个 HTTP 和反向代理服务器,同时也是一个邮件代理服务器和通用的 TCP 代理服务器.作为一个免费开源的服务器,Ngi ...
- 误导人的接口(interface)
接口,interface,这个词语有误导之嫌.窃以为,这也是其名称与实际开发不符,造成难于直观理解和使用过程中产生困惑的根源.所谓名不正则言不顺:不怕生错命,最怕改坏名. 在现实生活中,接口通常是指将 ...