Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Documention Change #1451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GramParallelo
Copy link

'With compare function' output was incorrect.

'With compare function' output was incorrect.
@jackmeagher
Copy link

This documentation change is incorrect. If you run this code yourself, you will see that the correct output actually is 42, 42.

Note the compare function: function (a,b) { return a !== b; }

Under the hood you can see why this is the case: when iterating over the events, the last emitted "distinct" event (by default, the first event MUST be distinct) is remembered as the "currentKey". While iterating, the key you're examining at any given point is compared to the currentKey. If they're the same, it skips the element you're examining. If they're different, it stores the element you're examining as the new currentKey and moves forward and repeats.

For the stream 42, 42, 24, 24, with the admittedly annoying comparison function, what happens is as follows:

42-42-24-24
^-----------
currentKey = null
emit 42
set currentKey := 42

42-42-24-24
---^--------
currentKey = 42
compare(currentKey, 42) == false
emit 42
set currentKey := 42

42-42-24-24
------^-----
currentKey = 42
compare(currentKey, 24) == true
skip

42-42-24-24
---------^--
currentKey = 42
compare(currentKey, 24) == true
skip

So as you can see, only 42s are emitted.

@gurghet
Copy link

gurghet commented Jul 27, 2017

well this is just plain confusing: if the objective is make people understand, having a comparison function a!==b without pointing it out is just tricking people.

@Reactive-Extensions Reactive-Extensions deleted a comment from msftclas Nov 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants