So I have an object of contactId and I convert it to flux and then I query the contact details using each Id respectively and after that convert it to Mono using collectList method and map it to another object let's call it DomainContactDetails like this.
Flux.just(identifier.regContactId, identifier.billingContactId ,identifier.adminContactId, identifier.techContactId)
.flatMap { resellerGetContact(it) }
.collectList()
.map { DomainContactDetails.fromList(it) }
.toFuture()
Are there anyways to collect flux element into key map instead of list. for now I'm using index of list to indentify which data belongs to the property
data class DomainContactDetails(
val registrantContact: ContactInfo,
val billingContact: ContactInfo,
val adminContact: ContactInfo,
val techContact: ContactInfo
) {
companion object {
fun fromList(contacts: List<ContactInfo>) = DomainContactDetails(
registrantContact = contacts[0],
billingContact = contacts[1],
adminContact = contacts[2],
techContact = contacts[3]
)
}
}
I want it to be key map so it might be a bit better like this
fun fromKeyMap(contacts: Map<String, ContactInfo>) = DomainContactDetails(
registrantContact = contacts["reg"],
billingContact = contacts["bil"],
adminContact = contacts["adm"],
techContact = contacts["tec"]
)
I'm not sure in your solution at all, but since you are asking about collecting to
Map
here is an answer. SeeFlux.collect()
operator:So, probably you just need to utilize an existing
Collectors.toMap()
API.