[RxJS] Filtering operator: filter

This lesson introduces filter: an operator that allows us to let only certain events pass, while ignoring others.

var foo = Rx.Observable.interval(1000);

/*
--0--1--2--3--4--5--6--7-
 filter(x => x % 2 === 0)
--0-----2-----4-----6----
*/

var bar = foo.filter(x => x % 2 === 0);

bar.subscribe(
  function (x) { console.log('next ' + x); },
  function (err) { console.log('error ' + err); },
  function () { console.log('done'); },
);
原文地址:https://www.cnblogs.com/Answer1215/p/5527518.html