zoukankan      html  css  js  c++  java
  • [RxJS] Filtering operators: skipWhile and skipUntil

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

    SkipWhile(predicate: function): Skip the value if meet the predicate function.

    var foo = Rx.Observable.interval(1000);
    /*
    --0--1--2--3--4--5--6--7--...
      skipWhile(x => x < 3).take(3)
    -----------3--4--5|
    */
    
    var bar = foo.skipWhile((x)=>{
                 return x<3;             
             }).take(3);
    
    bar.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );
    
      /*
    "next 3"
    "next 4"
    "next 5"
    "done"
      */

    skipUntil(Observable): after 3 seconds, click the start button, to start the foo observalbe.

    var foo = Rx.Observable.interval(1000);
    var start$ = Rx.Observable.fromEvent(document.querySelector('#start'), 'click');
    /*
    --0--1--2--3--4--5--6--7--...
      skipUntil(start$)
    -----------3--4--5|
    */
    
    var bar = foo.skipUntil(start$);
    
    bar.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );
    
      /*
    "next 3"
    "next 4"
    "next 5"
    "done"
      */
  • 相关阅读:
    双网卡绑定一个IP--bond
    查看window系统电脑连接过的wifi密码
    python字符串
    三级菜单
    购物车
    登录接口
    Python 基础之在ubuntu系统下安装双版本python
    SSH连接linux时,长时间不操作就断开的解决方案
    python中变量None的
    查找文件工具find
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5528061.html
Copyright © 2011-2022 走看看