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):
  1. var foo = Rx.Observable.interval(100);
  2.  
  3. /*
  4. --0--1--2--3--4--5--6--7-
  5. take(5)
  6. --0--1--2--3--4
  7. */
  8.  
  9. var bar = foo.take(5);
  10.  
  11. bar.subscribe(
  12. function (x) { console.log('next ' + x); },
  13. function (err) { console.log('error ' + err); },
  14. function () { console.log('done'); },
  15. );
  16.  
  17. /**
  18. "next 0"
  19. "next 1"
  20. "next 2"
  21. "next 3"
  22. "next 4"
  23. "done"
  24. */

first():

  1. var foo = Rx.Observable.interval(100);
  2.  
  3. /*
  4. --0--1--2--3--4--5--6--7-
  5. first()
  6. --0
  7. */
  8.  
  9. var bar = foo.first();
  10.  
  11. bar.subscribe(
  12. function (x) { console.log('next ' + x); },
  13. function (err) { console.log('error ' + err); },
  14. function () { console.log('done'); },
  15. );
  16.  
  17. /**
  18. "next 0"
  19. "done"
  20. */

skip(number): different with take(), it skip the first number of item, and show the rest:

  1. var foo = Rx.Observable.interval(100);
  2.  
  3. /*
  4. --0--1--2--3--4--5--6--7
  5. skip(5).take(3)
  6. -----------------5--6--7
  7. */
  8.  
  9. var bar = foo.skip(5).take(3);
  10.  
  11. bar.subscribe(
  12. function (x) { console.log('next ' + x); },
  13. function (err) { console.log('error ' + err); },
  14. function () { console.log('done'); },
  15. );
  16.  
  17. /**
  18. "next 5"
  19. "next 6"
  20. "next 7"
  21. "done"
  22. */

[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. 更改input【type=file】样式

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. ExecuteNonQuery()返回值

    查询某个表中是否有数据的时候,我用了ExecuteNonQuery(),并通过判断值是否大于0来判断数据的存在与否.结果与我所设想的很不一致,调试时才发现,其执行后返回的结果是-1,对此我很是不理解, ...

  3. Android 网络通信 HTTP

    摘要 1. Http GET 方法访问网站 2. Http POST访问网站 3. HttpClient进行Get方式通信 4. HttpClient进行Post方式通信 -------------- ...

  4. 关于java reflect

    反射的基石 Class类 对比提问: Person类代表人,它的实例对象就是张三,李四这样一个个具体的人, Java程序中的各个Java类属于同一类事物,描述这类事物的Java类名就是Class.对比 ...

  5. User Commands

    archive Creates a hadoop archive[v.存档; n.档案文件; 档案室; ]. More information can be found at Hadoop Archi ...

  6. Sharepoint 问题集锦 - external list (外部列表)

    使用Sharepoint开发过程中遇到的问题总结. 错误1: Unable to display this Web Part. To troubleshoot the problem, open th ...

  7. 《深入剖析Tomcat》阅读(一)

    第一章 一个简单的Web服务器 该应用程序仅接受位于指定目录的静态资源的请求,如HTML文件和图像文件.它也可以将传入的HTTP请求字节流显示到控制台上.但是,它并不发送任何头信息到浏览器,如日期或者 ...

  8. [HDOJ 5183] Negative and Positive (NP) 【Hash】

    题目链接:HDOJ - 5183 题目分析 分两种情况,奇数位正偶数位负或者相反. 从1到n枚举,在Hash表中查询 Sum[i] - k ,然后将 Sum[i] 加入 Hash 表中. BestCo ...

  9. 如何监控 Nginx?

    什么是 Nginx? Nginx("engine-x")是一个 HTTP 和反向代理服务器,同时也是一个邮件代理服务器和通用的 TCP 代理服务器.作为一个免费开源的服务器,Ngi ...

  10. 误导人的接口(interface)

    接口,interface,这个词语有误导之嫌.窃以为,这也是其名称与实际开发不符,造成难于直观理解和使用过程中产生困惑的根源.所谓名不正则言不顺:不怕生错命,最怕改坏名. 在现实生活中,接口通常是指将 ...