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. UEditor配置图片上传

    最近项目中需要用到一个图文编辑器功能,因为之前的kingeditor功能过于简陋,所以决定换成Ueditor,前端已经配置好了,这个是后台配置 1,确定前台已经配置好了 2,将编辑器的插件包下载下来, ...

  2. Ubuntu 误改/etc/sudoers 文件权限

    添加用户时不小心修改了/etc/sudoers 权限,结果不能sudo了,Ubuntu默认关闭root帐户,结果傻X了,无法改回了. 方法如下: 1.重启机器,开机按ESC,进入恢复模式 2.此时,磁 ...

  3. Python核心编程2第三章课后练习

    1. 标识符.为什么Python 中不需要变量名和变量类型声明? Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程.每个变量在内存中创建,都包括变量的标识,名称和数据这些信息.每 ...

  4. 【C语言】重定向和文件

    重定向和文件 一.相关基础知识 重定向:在计算机领域,重定向是大多数命令行解释器所具有的功能,包括各种可以将标准流重定向用户规定地点的Unix shells. 输入重定向:可以使程序能够使用文件代替键 ...

  5. jsconsole

    在移动设备或者其他无法启动 chrome developer tools 的时候可以用以下方法进行console 步骤: 1. 进入 http://jsconsole.com 的console画面,在 ...

  6. Github、Jekyll 搭建及优化静态博客方法指南

    尝试自己写 Blog 的人,一般会经历三个阶段. 第一阶段,刚接触 Blog,觉得很新鲜,试着选择一个免费空间来写. 第二阶段,发现免费空间限制太多,就自己购买域名和空间,搭建独立博客. 第三阶段,觉 ...

  7. /etc/shadow字段详解

    1)/etc/shadow 概说: /etc/shadow文件是/etc/passwd 的影子文件,这个文件并不由/etc/passwd 而产生的,这两个文件是应该是对应互补的:shadow内容包括用 ...

  8. C++中结构体与类的区别(结构不能被继承,默认是public,在堆栈中创建,是值类型,而类是引用类型)good

    结构是一种用关键字struct声明的自定义数据类型.与类相似,也可以包含构造函数,常数,字段,方法,属性,索引器,运算符和嵌套类型等,不过,结构是值类型. 1.结构的构造函数和类的构造函数不同. a. ...

  9. Android如何正确的保存文件

    在Android 官方开发文档中有一篇文档来介绍如何保存应用的数据,但笔者用过很多程序(从知名的到不知名的)处理的都不是很完美,或者 没有按照Android 开发团队建议的方式去保存他们应用的数据.当 ...

  10. 一个漂亮的DIV搜索条

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...