Skip to content

feat: Add dropRepeated stream operator. #1868

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

Merged
merged 1 commit into from
May 28, 2025
Merged

Conversation

He-Pin
Copy link
Member

@He-Pin He-Pin commented May 25, 2025

Motivation:
Add dropRepeated stream operator.

refs: #1662

@He-Pin He-Pin added the t:stream Pekko Streams label May 25, 2025
@He-Pin He-Pin added this to the 1.2.0-M2 milestone May 25, 2025
@He-Pin He-Pin force-pushed the distinct branch 2 times, most recently from 4793dc5 to b129c0d Compare May 25, 2025 14:51
@He-Pin He-Pin requested a review from pjfanning May 25, 2025 14:59
@He-Pin
Copy link
Member Author

He-Pin commented May 27, 2025

@pjfanning Would you like to give another round of review on this? I want to add aggregateUntilChanged once this is merged.

@pjfanning
Copy link
Contributor

Is there a reason not to just call this distinct? I don't get what the UntilChanged bit adds to this - ie it seems unnecessary and potentially confusing.

@raboof
Copy link
Member

raboof commented May 27, 2025

Is there a reason not to just call this distinct? I don't get what the UntilChanged bit adds to this - ie it seems unnecessary and potentially confusing.

I think we should try and avoid confusion with https://www.scala-lang.org/api/3.7.0/scala/collection/SeqOps.html#distinct-0

I understand the name follows https://rxjs.dev/api/operators/distinctUntilChanged . I'm not sure it makes sense to me: the results aren't 'distinct' 'until' they are the same? I don't want to bikeshed too much, but something like `dropRepeated' might make more sense? We can mention in the docs that this is called distinctUntilChanged in rx so people can find it.

The docs for 'statefulMap' have this as an example (https://pekko.apache.org/docs/pekko/current/stream/operators/Source-or-Flow/statefulMap.html). There's something to be said for having it as a separate construct, but perhaps the docs should link to each other?

@He-Pin
Copy link
Member Author

He-Pin commented May 27, 2025

@pjfanning I'm following the naming in reactor-core and smallrye/smallrye-mutiny#1853, rxjava is using this name too.

The main reason to add more operator is because when reading the code of Spring-Ai, and I found these operators are quite common, I hope someone will choose pekko to build scala's Spring-Ai

And we are building our mcp server at work too:)

@pjfanning
Copy link
Contributor

Is there a reason not to just call this distinct? I don't get what the UntilChanged bit adds to this - ie it seems unnecessary and potentially confusing.

I think we should try and avoid confusion with https://www.scala-lang.org/api/3.7.0/scala/collection/SeqOps.html#distinct-0

I understand the name follows https://rxjs.dev/api/operators/distinctUntilChanged . I'm not sure it makes sense to me: the results aren't 'distinct' 'until' they are the same? I don't want to bikeshed too much, but something like `dropRepeated' might make more sense? We can mention in the docs that this is called distinctUntilChanged in rx so people can find it.

The docs for 'statefulMap' have this as an example (https://pekko.apache.org/docs/pekko/current/stream/operators/Source-or-Flow/statefulMap.html). There's something to be said for having it as a separate construct, but perhaps the docs should link to each other?

I suppose that this function is not then the same as distinct and I think dropRepeated makes a lot more sense than distinctUntilChanged

@He-Pin
Copy link
Member Author

He-Pin commented May 27, 2025

@pjfanning @pjfanning And in Kotlin flow, it's distinctUntilChanged ,but in FS2, it's filterWithPrevious.

and changes and changesWith in ZIO

Which name do you prefer, actually, I don't like the distinctUntilChanged either:)

@He-Pin He-Pin requested a review from raboof May 27, 2025 16:52
@raboof
Copy link
Member

raboof commented May 27, 2025

I could live with changes or dropRepeated. (I don't think we need an equivalent of changesWith, people can use statefulMap for more advanced use cases)

@He-Pin He-Pin changed the title feat: Add distinctUntilChanged stream operator. feat: Add dropRepeated stream operator. May 28, 2025
@He-Pin
Copy link
Member Author

He-Pin commented May 28, 2025

@pjfanning @raboof I have update to dropRepeated

@He-Pin
Copy link
Member Author

He-Pin commented May 28, 2025

@pjfanning Thanks

@He-Pin He-Pin requested a review from pjfanning May 28, 2025 17:16
Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin He-Pin merged commit e6662e1 into apache:main May 28, 2025
9 checks passed
@He-Pin He-Pin deleted the distinct branch May 28, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t:stream Pekko Streams
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants