Behavior of #zip with #groupBy & #publish #978
Comments
@Nupf This example works for me: var parent = Rx.Observable.from([1,2,3]).publish();
var child = parent.map(x => x).publish();
var groupedParent = parent.groupBy(x => x).flatMap(x => x);
var groupedChild = child.groupBy(x => x).flatMap(x => x);
Rx.Observable.zip([groupedParent, groupedChild])
.subscribe(x => {
console.log('zipped parent ' + x); // -> nothing
console.log('zipped child ' + x); // -> emits
});
groupedChild.subscribe(value => {
console.log('child ' + value); // -> emits
});
groupedParent.subscribe(value => {
console.log('parent ' + value); // -> emits
});
child.connect();
parent.connect(); |
@xgrommx I need to zip groups together. The goal is to xprod the elements of the zipped together groups - so parent_group1 with child_group1, parent_group2 with child_group2, etc. Rx.Observable.zip([groupedParent, groupedChild])
.flatMap(groups => xprod(groups[0], groups[1]))
.subscribe(); xprod being the function described in #807. |
@Nupf I'm not sure that is what you want but try it: var groupedParent = parent.groupBy(x => x).flatMap(group => group.toArray());
var groupedChild = child.groupBy(x => x).flatMap(group => group.toArray());
Rx.Observable.zip([groupedParent, groupedChild])
.flatMap(groups => Rx.Observable.from(groups[0]).concatMap(x => Rx.Observable.from(groups[1]), (x, y) => [x, y]))
.subscribe(x => console.log(x)); |
That works. Thanks! Do you know why nothing is emitted in the original example? It doesn't make sense to me. Rx.Observable.zip([groupedParent, groupedChild])
.subscribe(groups => {
groups[0].subscribe(x => console.log('zipped parent ' + x)); // -> nothing
groups[1].subscribe(x => console.log('zipped child ' + x)); // -> emits
}); |
Ok, so here's what I've got: http://stackoverflow.com/questions/33193130/rxjs-zip-groups-created-using-groupby The parent groups inside .zip doesn't emit values, because it has already emitted its values BEFORE it's subscribed to. Why is that? That behavior seems wrong to me but apparently it should be expected stackoverflow question. Something similar happens when using .combineLatest to combine the groups: var parent = Rx.Observable.from([1,2,3,4,5,6]).publish();
var child = parent.map(x => x).publish();
var groupedParent = parent.groupBy(x => x);
var groupedChild = child.groupBy(x => x);
Rx.Observable.combineLatest([groupedParent, groupedChild])
.subscribe(groups => {
groups[0].subscribe(x => console.log('zipped parent ' + x)); // emits everything but the first value
groups[1].subscribe(x => console.log('zipped child ' + x)); // emits correctly
});
child.connect();
parent.connect(); Is it even possible to achieve what I've tried in the first post? |
Why does only the grouped observable of child emit values when zipped?
When subscribing to the grouped observables on their own, both emit their respective values
see https://jsbin.com/coqeqaxoci/edit?js,console
The text was updated successfully, but these errors were encountered: