Updating your snippet, you can simply do something like this:
Rx.Observable.of(1)
.map(x=>{
var y = x * 2;
return {x, y};
})
.subscribe(res=>{
console.log(res.x, res.y);
})
Or, if in the map you intended to use an Observable:
Rx.Observable.of(1)
.switchMap(x=> {
var y = x * 2;
return Rx.Observable.of({x, y});
})
.subscribe(res=>{
console.log(res.x, res.y);
})
And using a function:
function simpleAndDouble$(x) {
var y = x * 2;
return Rx.Observable.of({x, y});
}
var obs1$ = Rx.Observable.of(1)
.switchMap(x=> simpleAndDouble$(x))
.subscribe(res=>{
console.log(res.x, res.y);
})
Update, as your request in comment:
const subscription = Rx.Observable.of(1)
.mergeMap(x =>
Rx.Observable.of(x * 2),
(x, y) => {
console.log(x, y);
})
.subscribe();
Update:
const one$ = Observable.of(1);
const two$ = one$.map(x => x * 2);
const subscription = Observable
.merge(one$, two$)
.map(n => [n])
.reduce((acc, val) => acc.concat(val), [])
.subscribe((a) => {
const [x, y] = a;
console.log('x:', x);
console.log('y:', y);
});
}