Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable execution. In this lesson we will see similar operators which refer instead to the end of an Observable execution, such as takeLast().

takeLast(number): takeLast requires the source has completion.

var foo = Rx.Observable.range(1,7);

/*
--0--1--2--3--4--5--6--7-|
takeLast(2)
---------------------------(67|)
*/ var bar = foo.takeLast(2); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next 6"
"next 7"
"done"
*/

If replace range() to interval(1000).take(7); then we will wait 7 seconds before the result comes out sync.

last():

var foo = Rx.Observable.range(1,7);

/*
--0--1--2--3--4--5--6--7-|
last()
---------------------------(7|)
*/ var bar = foo.last(); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next 7"
"done"
*/

[RxJS] Filtering operators: takeLast, last的更多相关文章

  1. [RxJS] Filtering operators: take, first, skip

    There are more operators in the filtering category besides filter(). This lesson will teach how take ...

  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: takeUntil, takeWhile

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

  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: skipWhile and skipUntil

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

  6. Rxjs常用operators

    本文使用的是angular6内置的rxjs,版本号为6.3.3 concat 通过顺序地发出多个 Observables 的值将它们连接起来,一个接一个的. 参数: 名称 类型 属性 描述 other ...

  7. [RxJS] Transformation operators: debounce and debounceTime

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

  8. [RxJS] Transformation operators: delay and delayWhen

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

  9. [RxJS] Creation operators: interval and timer

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

随机推荐

  1. 解决SDK Manager无法更新问题

    因为google被封了,导致Android SDK Manager无法更新,解决方案如下: 1.选择tools->options,跳出Settings页面 2.设置HTTP Proxy代理,设置 ...

  2. mysql慢速查询

    linux下配置慢查询: 修改my.cnf文件,在[mysqld]模块下添加 #slow_query_log=1 有些人说这个是slow_query的开关,但是我加上以后提示错误.log_slow_q ...

  3. mac+eclipse+svn+maven经验总结(转)

    1.Eclipse for Mac:http://mirrors.ustc.edu.cn/eclipse/technology/epp/downloads/release/indigo/SR2/ecl ...

  4. oracle excute immediate 单引号转义

    excute immedaite 后接单引号,但是遇到 add xxx default ' ' ,命令中还有单引号的情况,需要转义.这时候不是用传统的 \ 反斜杠来转义,而是用 单引号转义 execu ...

  5. <jsp:forward>、requestDispatcher和sendRedirect()的区别

    1.会话信息保存在服务器内存上,可以断续访问,和cookie相比,其保存在服务器上. 2.男人就像蓝牙:只有在你接近时,他才会找上你.当你离开后,他便又去找其他的"设备"了.女人就 ...

  6. 自定义元素–为你的HTML代码定义新元素

    注意:这篇文章介绍的 API 尚未完全标准化,并且仍在变动中,在项目中使用这些实验性 API 时请务必谨慎. 引言 现在的 web 严重缺乏表达能力.你只要瞧一眼“现代”的 web 应用,比如 GMa ...

  7. 【POJ1021】Intervals (最短路解差分约束)

    题目: Sample Input 5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1 Sample Output 6 题意: 我们选数,每个数只能选一次.给定n个条件[ai,bi]和 ...

  8. 关于Cookie跨域操作的一些总结

    正常的cookie只能在一个应用中共享,即一个cookie只能由创建它的应用获得. 1.可在同一应用服务器内共享方法:设置cookie.setPath("/");     本机to ...

  9. VLD(Visual LeakDetector)内存泄露库的使用

    VLD简介 由于C/C++语言没有所谓的垃圾收集器,内存的分配和释放都需要程序员自己来控制,这会给C/C++程序员带来一定的困难.当您的程序越来越复杂时,它的内存管理也会变得越来越困难.内存泄漏.内存 ...

  10. SQL server聚合函数、数学函数、字符串函数

    一.基础语句 二.数学函数与字符串函数 三.练习 1.创建一个学生信息表,根据要求写出程序 2.新建一个超市表,进了十种商品,个数都是十件