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.

 take(number):
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的更多相关文章

  1. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...

  2. [RxJS] Filtering operators: distinct and distinctUntilChanged

    Operator distinct() and its variants are an important type of Filtering operator. This lessons shows ...

  3. [RxJS] Filtering operators: skipWhile and skipUntil

    After takeUntil() and takeWhile() function, let's have a look on skipWhile() and skilUntil() functio ...

  4. [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 ...

  5. [RxJS] Filtering operators: takeUntil, takeWhile

    take(), takeLast(), first(), last(), those opreators all take number or no param. takeUtil and takeW ...

  6. [RxJS] Transformation operators: debounce and debounceTime

    Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...

  7. [RxJS] Transformation operators: delay and delayWhen

    This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...

  8. [RxJS] Creation operators: interval and timer

    It is quite common to need an Observable that ticks periodically, for instance every second or every ...

  9. [RxJS] Creation operators: empty, never, throw

    This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...

随机推荐

  1. javascript 获取 class 样式 重新赋值class样式 为div等系列标签内更改内容

    name = document.getElementById(project_not_through_id).className;                     // 获取目标id的 cla ...

  2. CANoe 入门 Step by step系列(二)CAPL编程【转】

    CAPL就是Communication Application Programming Laguage的缩写,CAPL类似于C语言的语法,因此所有的语法请参考C语言教程,这里不在这里进行详述,关于C语 ...

  3. 2016022611 - redis订阅发布命令集合

    redis消息订阅发布命令 参考地址:http://www.yiibai.com/redis/redis_pub_sub.html 消息发送者发送消息,通过redis的channal,消息接收者获取消 ...

  4. SecurityCRT输出日志重定向

    使用CRT进行抓取log,因为工具本省缓冲区有限,导致,刷屏特别快,可能会错过一些log,可以对CRT的log进行增加输出源,或者说将输出到控制台的log再输出到本地文件中: 文件->点击(勾选 ...

  5. 配置公网的域名绑定IP

    1. 在万网.美橙申请了一个域名,当然付完费了.   2. 点击"管理",找到了域名解析   3. 点击"域名解析"   注意"记录值",这 ...

  6. QT事件过滤器(QT事件处理的5个层次:自己覆盖或过滤,父窗口过滤,Application过滤与通知)

    Qt事件模型一个真正强大的特色是一个QObject 的实例能够管理另一个QObject 实例的事件. 让我们试着设想已经有了一个CustomerInfoDialog的小部件.CustomerInfoD ...

  7. DEEPIN 2014 正式版 试用体验

    7月6日深度正式发布 Deepin 2014 操作系统,该系统是基于 Ubuntu 14.04 LTS 的 Linux 发行版,并搭载了多款深度开发的软件,更符合国人使用习惯.由于Deepin 201 ...

  8. ajax post data 获取不到数据,注意 content-type的设置

    ajax post  data  获取不到数据,注意 content-type的设置 .post/get关于 jQuery data 传递数据.网上各种获取不到数据,乱码之类的.好吧今天我也遇到了,网 ...

  9. [cocos2d] 谁摸了我一下----触摸事件处理

    1. 设置接受触摸事件,可在init方法里面写上 [self setTouchEnabled: YES]; 旧版为self.isTouchEnabled = YES; xcode会报Deprecati ...

  10. MonkeyRunner 连续两次点击报“Error sending touch event”

    最近用monkeyrunner做自动化测试,遇到连续两次点击,第二次点击就会报错“Error sending touch event”. 具体做法如下: device.touch(234,112, ' ...