Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and implement tests for used to named unique now distincByDocId function #309

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

lenguyenthanh
Copy link
Member

No description provided.

Seperate functionality of unique function from ChangeStreamDocument
@lenguyenthanh
Copy link
Member Author

lenguyenthanh commented Sep 9, 2024

Hi @gravetii, I refactored and added tests for unique function and just realized the old implementation was subtly (but seriously) wrong.

Let's look at this:

  def unique: List[ChangeStreamDocument[A]] =
    changes
      .foldRight(List.empty[ChangeStreamDocument[A]] -> Set.empty) { case (change, p @ (acc, ids)) =>
        if change.docId.exists(!ids.contains(_))
        then (change :: acc) -> (ids + id)
        else p
      }
      ._1

inside unique, id at line 6 just appeared without any reference. It was still compiled because We have an id function in the same file (which is my bad).

p/s: I mentioned this for the shake of the correctness and not for blaming you. Thanks to your effort, I finally sit down and write tests which I should've done for a long time.

@gravetii
Copy link
Contributor

gravetii commented Sep 9, 2024

Indeed @lenguyenthanh, you're too kind. apologies for the chaos, the change looks good to me!

@lenguyenthanh
Copy link
Member Author

Indeed @lenguyenthanh, you're too kind. apologies for the chaos, the change looks good to me!

thanks, and please keep contributing, we're really appreciated your contribution!

@lenguyenthanh lenguyenthanh changed the title Fix and implement tests for used to named unique now distincByDocId functions Fix and implement tests for used to named unique now distincByDocId function Sep 9, 2024
@lenguyenthanh lenguyenthanh merged commit a9e0728 into master Sep 9, 2024
3 checks passed
@lenguyenthanh lenguyenthanh deleted the has-doc-id branch September 9, 2024 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants