Context: To generate swift code using a JSON tree I’m traversing the tree in pre-order format reaching down into all the leaf nodes, effectively flattening the tree into an array.
Description: Using Rx.Observable.generate() to create an observable stream from the array element, but when filtering I'm getting some weird results. I’ve provided a boiled down example below:
Example:
var Rx = require('/usr/local/lib/node_modules/rx') // 4.0.7
// source 1,3,5,7,9 (WAT)
var source = Rx.Observable.generate(
0,
function (x) { return x < 10; },
function (x) { return x + 1; },
function (x) { return x; }
)
// filter & merge
var a = source.filter(x => x % 2 == 0)
var b = source.filter(x => x % 2 != 0)
var source = a.merge(b)
// subscribe & output
var subscription = source.subscribe(
x => console.log(x)
)
Question: Why do I get the output result 1,3,5,7,9 and not 0,1,2,3,4,5,6,7,8,9 as expected?
It doesn’t seem to matter which way I apply the merge… I also get the output 0,2,4,6,8 when reversed.
Edit, npm install & node version user3743222: thanks for your feedback, info on project follows:
$ npm install
chai@3.4.1 node_modules/chai
├── assertion-error@1.0.1
├── type-detect@1.0.0
└── deep-eql@0.1.3 (type-detect@0.1.1)
moment@2.11.1 node_modules/moment
mocha@2.3.4 node_modules/mocha
├── escape-string-regexp@1.0.2
├── diff@1.4.0
├── commander@2.3.0
├── supports-color@1.2.0
├── growl@1.8.1
├── debug@2.2.0 (ms@0.7.1)
├── jade@0.26.3 (commander@0.6.1, mkdirp@0.3.0)
├── mkdirp@0.5.0 (minimist@0.0.8)
└── glob@3.2.3 (inherits@2.0.1, graceful-fs@2.0.3, minimatch@0.2.14)
rx@4.0.7 node_modules/rx
$ node --version
v4.2.1