I have two Flux with 2 different data types as shown below:
Flux<Dog> dogs = loadDogsFromFile()
Flux<Man> men = loadMenFromFile()
data class Dog(
val name: String,
val ownerName: String,
)
data class Man(
val name: String,
val dogOwnerName: String,
)
As you can see the one field we can use to match these two Flux objects is dogOwnerName. Right now this is how I am comparing them
val disposable = dogs.flatMap { dog ->
men.map { man->
val isEqual = comparator(dog, man)
Triple(dog, man, isEqual)
}
}.filter {x -> x.third === true }
This gets the job done but it is nowhere efficient, it keeps looping even after the desired fields are found and because of that, we have to use a filter operator to only get what we need.
Edit
Based on @marstran comment on the user input, I have large JSON files that contain dogs and men that I'm loading here:
Flux<Dog> dogs = loadDogsFromFile()
Flux<Man> men = loadMenFromFile()
After matching the dogs to their owners/men I'm building an object that I'm saving to the database like this:
val disposable = dogs.flatMap { dog ->
men.map { man->
val isEqual = comparator(dog, man)
Triple(dog, man, isEqual)
}
}.filter {x -> x.third === true }
.map{(dog,man,isEqual) ->
DogOwner(man,dog)
}.doOnNext{dogOwner -> dogOwnerRepository.save(dogOwner)}