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
[email protected] node_modules/chai
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])
[email protected] node_modules/moment
[email protected] node_modules/mocha
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected])
[email protected] node_modules/rx
$ node --version
v4.2.1