Reputation: 1828
I have two fluxes and I want to merge them avoiding duplicates. How can I do this?
Here are my fluxes:
Flux<Tweet> remoteTweets = Flux.just(
new Tweet("tag1",new TweetID("text","name"),"userimage","country","place"),
new Tweet("tag2",new TweetID("text","name"),"userimage","country","place")
);
Flux<Tweet> localTweets = Flux.just(
new Tweet("tag1",new TweetID("text","name"),"userimage","country","place")
);
Merging these two is giving me tag 1, tag1, tag2
, but I want tag1, tag2
.
The order is not important.
Upvotes: 1
Views: 3385
Reputation: 1702
you can do it like this
SpringApplication.run(BackendApplication.class, args);
String[] strings = {"a","b","c"};
Flux.merge(Flux.fromArray(strings),Flux.fromArray(strings))
.distinct()
.map(s -> {
System.out.println(s);
return s;
}).subscribe();
but in your case in Tweet object you need to override equals and hashcode be aware distinct firstly see if hashcode is equal then .equal function
if you are using intellij try alt+ insert and click equal and hashCode
Upvotes: 4