zoukankan      html  css  js  c++  java
  • [RxJS] Transformation operator: map and mapTo

    We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't need it because it's too specific: it only does simple multiplication on numbers. In this lesson we will see how the map() operator is useful for any calculation on delivered values.

    map:

    var foo = Rx.Observable.interval(1000);
    
    /*
    
    foo: ---0---1---2---3--...
           map(x => x / 2)
    bar: ---0---2---4---6--...
    
    */
    
    // map take a function
    var bar = foo.map(x => x / 2);
    
    bar.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );

    mapTo:

    var foo = Rx.Observable.interval(1000);
    
    /*
    
    foo: --- 0---1--- 2--- 3--...
           mapTo(10)
    bar: ---10---10---10---10--...
    
    */
    
    // mapTo take a value
    var bar = foo.mapTo(10);
    
    bar.subscribe(
      function (x) { console.log('next ' + x); },
      function (err) { console.log('error ' + err); },
      function () { console.log('done'); },
    );
  • 相关阅读:
    shell awk
    spl_autoload_register array参数
    install xdebug on fedora
    call_user_func
    转载 shell sort
    通过nginx + lua来统计nginx上的监控网络请求和性能
    nginx 知识点
    python 发送带附件的 邮件
    xdebug php
    关于ZendStudio 10.5的破解
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5524725.html
Copyright © 2011-2022 走看看