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. about python

    函数式编程 λ演算 LISP,Erlang 尾递归 栈的使用 避免防御式编程 ER实体Entity关系relationship OOP [OOA/D] 属性.行为 继承.聚合.关联 抽象.封装 笛卡尔 ...

  2. android 代码混淆及问题大集锦

    最近在需要对所开发的项目进行了代码混淆,在android studio中开启代码混淆其实还是挺方便的,不过因为代码混淆产生的问题非常多,特别是对于一些涉及到反射的第三方库经常因为名称的变化导致无法使用 ...

  3. Cow Marathon

    poj1985:http://poj.org/problem?id=1985 题意:就是树的直径. 题解:直接DFS即可. #include<iostream> #include<c ...

  4. css li 列表

    ul,li{list-style-type:none;padding:0;margin:0}

  5. 14.6.4 Configuring the Memory Allocator for InnoDB 配置InnoDB 内存分配器

    14.6.4 Configuring the Memory Allocator for InnoDB 配置InnoDB 内存分配器 当InnoDB 被开发时,内存分配提供了操作系统和 run-time ...

  6. 如何给循环中的对象添加事件--深入理解JavaScript的闭包特性

    初学者经常碰到的,即获取HTML元素集合,循环给元素添加事件.在事件响应函数中(event handler)获取对应的索引.但每次获取的都是最后一次循环的索引.原因是初学者并未理解JavaScript ...

  7. CnPack for delphi xe5

    CnPack Team is made up of Chinese Programmers and Delphi / C++ Builder fans across the Internet. Our ...

  8. C++中关于const的思考

    在学习C++的过程中,经常被什么时候使用const.为什么使用const以及怎么使用const关键字这样的问题所困扰,以下是我对const的使用总结. 1.值替代 使用#define的确单缺点,第一: ...

  9. 合并两个rs结果输出

    <%Const SqlDatabaseName = "DNN625"       ' 数据库名字' Const SqlPassword     = "123456& ...

  10. LOL游戏程序中对一些函数的Hook记录(Win10 x64)

    [PC Hunter Standard][League of Legends.exe-->Ring3 Hook]: 108Hooked Object Hook Address and Locat ...