I am trying to use groupBywith RxJs and I need to use objects as keys. If I do not, and I use, for example, simple strings like this:
var types = stream.groupBy(
function (e) { return e.x; });
then everything will be fine, and my subscription is called once and once for each other key. But if I try to use objects, the subscription is called for each item from stream, even if the key turns out to be the same as the previous ones.
Of course, there is a problem with equality of objects, but I am embarrassed because I do not understand how to use additional arguments for groupBy. The latest version of the docs says that there is a third argument that can be a comparator, but it is never called. Earlier, docs talked about a key serializer, which is a completely different idea, but none of the methods work for me.
Having looked at the source code of Rx, I see attempts to test the function getHashCode, but I cannot find and document it. Code like this:
var types = stream.groupBy(
function (e) {
return { x: e.x, y: e.y };
},
function (e) { return e; },
function (...) { return ???; });
- this is what I'm trying to write, but not luck, and everything that I set for the third callback is not called.
What is wrong here?
source
share