Conversation
…n element occurs multiple times in the input stream
Contributor
|
I'll take a proper look later when home, but looks good. Does this dedupe per-key? So to dedupe the all you key by a common key first? |
Contributor
|
Not a problem if it doesn't, we can always add a version that does if we want to later in. |
Contributor
Author
It dedupes by the entire value unless you pass an extractor function in which case it dedupes by the return value of that function. The extractor function pattern should be general enough to handle any case. So, if you want to dedup by key you would do |
cursor bot
pushed a commit
to samwillis/d2ts
that referenced
this pull request
Jul 13, 2025
* Replace distinct operator atop reduce by a dedicated more efficient distinct operator * Add additional unit tests for distinct operator * Fix bug where distinct wasn't properly summing the multiplicites if an element occurs multiple times in the input stream * Extend distinct with optional argument to determine what to deduplicate by. * Formatting * Small change to test * changest --------- Co-authored-by: Sam Willis <sam.willis@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR replaces the existing
distinctoperator which was built on top of thereduceoperator with a more efficient implementation. This newdistinctoperator supports an optional argument that is a function(value: T) => anyto determine what to deduplicate on. For example, we can do:Note that the output has the same type as the input, the function is only used to determine what to deduplicate on but it is not used to transform the values. This function is very useful for ts/db where we want to get distinct results based on the selected columns but we still want the entire selected rows to come out of the stream.