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

distinctBy but with last element #2712

Open
ckosmowski opened this issue Mar 3, 2022 · 1 comment
Open

distinctBy but with last element #2712

ckosmowski opened this issue Mar 3, 2022 · 1 comment

Comments

@ckosmowski
Copy link

I am currently evaluating vavr as a replacement for Java 8 Streams. While processing batches of events we always want to keep the last value unique by some key. The semantics would be the same as

.reverse()
.dicstinctBy(e -> e.getSomeKey())
.reverse()

i think.

But i do think that this comes with performance hits. To achieve this we are using a LinkedHashMap where we put elements one after the other with their generated keys and afterwards get the .values() again from that map which will now contain only the last elements of each key.

Would you consider adding "distinctByLast" or as we call it "keepLast" ?

@pivovarit
Copy link
Member

pivovarit commented Oct 11, 2024

That sounds like a good idea :) I'd lean towards a new distinctByKeepLast method for the sake of backward compatibility. We could target 0.11 and 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants