码迷,mamicode.com
首页 > Web开发 > 详细

[RxJS] Split an RxJS Observable into groups with groupBy

时间:2016-12-23 07:46:56      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:out   with   routing   learn   tor   pre   count()   work   into   

groupBy() is another RxJS operator to create higher order observables. In this lesson we will learn how groupBy works for routing source values into different groups according to a calculated key.

 

const numbersObservable = Rx.Observable.interval(500).take(5);

numbersObservable
  .groupBy(x => x % 2)
  .map(innerObs => innerObs.count())
  .mergeAll()
  .subscribe(x => console.log(x));

/*
--0--1--2--3--4|

 groupBy(x => x % 2)
 
--+--+---------|
  \    \  1-----3---|
  0-----2-----4|
  
 map(innerObs => innerObs.count())
 
--+--+---------|
  \    \  ---------2|
  ------------3|
  
 mergeAll
 
--------------(3,2)|

*/

 

[RxJS] Split an RxJS Observable into groups with groupBy

标签:out   with   routing   learn   tor   pre   count()   work   into   

原文地址:http://www.cnblogs.com/Answer1215/p/6213448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!