[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 ...
随机推荐
- 博客系统-3.0CodeIgniter系统SAE版本的配置 application/config/
autoload.php(系统启动时自动加载的文件:包,类库,驱动,方法助手,配置) $autoload['libraries'] = array('database', 'access', 'pag ...
- 随机List中数据的排列顺序
把1000个数随机放到1000个位置. 这也就是一个简单的面试题.觉得比较有意思.就顺带写一下 举个简单的例子吧. 学校统一考试的时候 有 1000个人,然后正好有 1000个考试位置,需要随机排列 ...
- Remote Direct Memory Access (RDMA)
RDMA有三类实现方式,包括RoCE,iWARP和InfiniBand.RDMA的基础是Virtual Interface Architechure (VIA). 参考文档: https://en.w ...
- spring与mybatis,strut2整合连接sqlserver不的不说的那点事儿
今天在通过spring与mybatis整合中,想连接下公司用的sqlserver数据库,结果使用Junit测发现没连上,于是就有了下面的问题: 准备工作都已经做好了 web中spring的监听配置了 ...
- [BZOJ 1016] [JSOI2008] 最小生成树计数 【DFS】
题目链接:BZOJ - 1016 题目分析 最小生成树的两个性质: 同一个图的最小生成树,满足: 1)同一种权值的边的个数相等 2)用Kruscal按照从小到大,处理完某一种权值的所有边后,图的连通性 ...
- PhoneGap + Dreamweaver 5.5 无法在模拟器中打开的问题(二)
转载:http://blog.csdn.net/dupang/article/details/8248335 按照网上的教程搭建Dreamweaver CS5.5+PhoneGap移动开发环境,在进行 ...
- 基于android的Socket通信
一.Socket通信简介 Android与服务器的通信方式主要有两种,一是Http通信,一是Socket通信.两者的最大差异在于,http连接使用的是“请求—响应方式”,即在请求时建立连接通道,当客户 ...
- cout输出字符串指针
先给出通过字符型指针输出字符串的示例代码,如下: #include <iostream>using std::cout;using std::endl; int main(){ const ...
- 坑爹的Android Ble 问题记录日志
开发Ble(公司项目,防丢器)已经有一段时间,由于是第一次接触Ble而网上资料又不多,且android平台自身的差异性,遇到了很多问题.为了将来方便查阅,在此做下记录.1.中兴手机,蓝牙手动断开后,无 ...
- css两句话搞定漂亮表格样式
CSS代码: table { background-color:#c0de98; width:500px; height:100px; } td { background-color:#ffffff; ...