Given the following MyObject and Flux<MyObject> what is the best way to remove MyObjects with same the same property from this flux?
import lombok.Data;
import reactor.core.publisher.Flux;
public class Example {
@Data
public class MyObject {
final String name;
final int priority;
}
public Example() {
Flux<MyObject> myFlux = Flux.just(
new MyObject("abc", 2),
new MyObject("abc", 4),
new MyObject("cde", 1));
}
}
For example I want to remove objects with same name while choosing the ones with higher priority.
Output: [Example.MyObject(name=abc, priority=4), Example.MyObject(name=cde, priority=1)]
If I use myFlux.distinct(MyObject::getName) I wont be able to choose which one to keep.