CombineLatest and withLatestFrom are both AND-style combination operators. In this lesson, we will learn about zip, our last AND-style combinator. It uses the n-th value of each member Observable to produce the n-th output value.

If you zip two observalbe. it will wait both n-th observalbe value emit, and combie them:

  • First of foo + First of bar =  first of output
  • Second of foo + Second of bar = Second of output
  • ...
  • n-th of foo + n-th of bar = n-th of output

It will never combine: n-th of foo + (n+1)-th of bar.

var foo = Rx.Observable.of('h', 'e', 'l', 'l', 'o');
var bar = Rx.Observable.interval(400).take(5); /*
(hello|) (foo)
---0---1---2---3---4| (bar)
zip((x,y) => x)
---h---e---l---l---o|
*/ //var combined = Rx.Observable.zip(foo, bar, (x,y) => x);
var combined = foo.zip(bar, (x,__)=> x); combined.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next h"
"next e"
"next l"
"next l"
"next o"
"done"
*/

[RxJS] Combination operator: zip的更多相关文章

  1. [RxJS] Combination operator: withLatestFrom

    Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...

  2. [RxJS] Combination operator: combineLatest

    While merge is an OR-style combination operator, combineLatest is an AND-style combination operator. ...

  3. [RxJS] Transformation operator: buffer, bufferCount, bufferTime

    This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...

  4. [RxJS] Transformation operator: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  5. rxjs自定义operator

    rxjs自定义operator

  6. [RxJS] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

  7. [RxJS] Utility operator: do

    We just saw map which is a transformation operator. There are a couple of categories of operators, s ...

  8. [RxJS] Creation operator: of()

    RxJS is a lot about the so-called "operators". We will learn most of the important operato ...

  9. [RxJS] Connection operator: multicast and connect

    We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...

随机推荐

  1. 帝国cms7.0修改“信息提示”框

    具体修改查看e/message/index.php文件 上传一张合适用的图 <table width="600" height="224" border= ...

  2. PM【terminal】

    More Knowledge More Performance More Time 资料模组化 以知识管理为基础的项目管理 规范:ethic

  3. ubuntu下openGL的配置方法

    This is a simple tutorial to show a new linux user (such as myself) how to setup freeglut and OpenGl ...

  4. How to install Pygame for Python 3.4 on Ubuntu 14.04(转)

    First run this to install dependencies: sudo apt-get install mercurial python3-dev python3-numpy \ l ...

  5. 无Xaml的WPF展示

    我们创建一个wpf应用程序,我们把里面的xaml文件全部删除,添加一个新类: 如下图: 然后我们cs文件中的代码: using System; using System.Collections.Gen ...

  6. 一个c++给程序打log的单例模式类

    开发过程中需要给程序打log. 所以照着网上写了个单例模式的log类 #ifndef MISCLOGWRITER_H_ #define MISCLOGWRITER_H_ #include <io ...

  7. The largest prime factor(最大质因数)

    1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number ...

  8. 不支持关键字: “userid”。

    运行程序提示:不支持关键字: “userid”. 找了很久在一篇博客里面提示web.config数据库字符串链接出错.

  9. Linux相关命令

    使用的是ubuntu 安装JDK   输入java 命令会有提示安装的软件列表 sudo apt-get install openjdk-6-jdk sudo rm file名 删除文件 sudo r ...

  10. JNI-Test

    //testdll.h/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header fo ...