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. laravel学习前期遇到的小知识点(1)

    1. 目前我用的laravel 5.2.36版本web中间件成为全局中间件(不知道从5.2.26以上就改变了还是怎样,没有深究),也就是之前的版本路由里默认会有一个Route::group的web中间 ...

  2. onethink 换空间报错 解决方案

    onethink 换空间的时候有两个配置文件 Application\Common\Conf Application\User\Conf 如果报错先测试数据库 <?php $con = mysq ...

  3. __name__ == '__main__'的作用

    当你打开一个.py文件时,经常会在代码的最下面看到if __name__ == '__main__':,现在就来介 绍一下它的作用. 模块是对象,并且所有的模块都有一个内置属性 __name__.一个 ...

  4. QPixmap,QImage图片大小缩放linux版

    注意事项: 1.装载图片的地址有时候会读取不到.可以多摸索一下当前系统对应的格式. 2.scaled缩放方式选择 3.注意保存路径.下面程序保存路径是当前执行文件目录中. PicOpera::PicO ...

  5. Spire.XLS

    又一款Excel处理神器Spire.XLS,你值得拥有(二)   前言:上篇 C#组件系列——又一款Excel处理神器Spire.XLS,你值得拥有 介绍了下组件的两个功能,说不上特色,但确实能解决我 ...

  6. CABAC

    CABAC(Context-based Adaptive Binary Arithmetic Coding),基于上下文的自适应二进制算术编码.CABAC是H.264/AVC标准中两种熵编码中的一种, ...

  7. 利用 Apache Synapse 模拟 Web 服务

    Apache Synapse 是一个简单.轻量级的高性能企业服务总线 (ESB),它是在 Apache Software Foundation 的 Apache License Version 2.0 ...

  8. ViewHolder VS HolderView ?

    ViewHolder 模式在 Android 中大家应该都不陌生了,特别是在 ListView 中通过 ViewHolder 来减少 findViewById 的调用和 类型的转换. 而 Holder ...

  9. Android 小闹钟程序

    最近写了个闹钟的程序,看到SharedPreferences在一个程序中可以共享数据,SharedPreferences是一个轻量级的键值存储机制,只可以存储基本数据类型.我就拿来用用,没想到Shar ...

  10. Mysql 8个小时连接断开问题解析

    wait_timeout — 指的是mysql在关闭一个非交互的连接之前所要等待的秒数,其取值范围为1-2147483(Windows),1-31536000(linux),默认值28800. int ...