I have a wrapper that may or may not contain data:
class EmailAdapter {
...
fun toEmail(): Optional<Email> {
val agencyContact = getAgencyContact()
return if (agencyContact.isPresent) {
Optional.of(Email(
contact = agencyContact.get()
))
} else {
Optional.empty()
}
}
}
I group one user to multiple contacts:
fun upsertAll(eMails: List<EmailAdapter>) {
val mailsByUser = eMails
.filter { adapter -> adapter.getUserContact().isPresent }
.filter { adapter -> adapter.getAgencyContact().isPresent }
.groupBy { adapter -> adapter.getUserContact().get() }
It groups val mailsByUser: Map<String, List<EmailAdapter>>
I want to group all emails to a unique user
I want to unwrap the EmailAdapter so that the relation is EmailAdapter.user -> List<EmailAdapter.mail>
or val mailsByUser: Map<String, List<Email>>
I fail in the last step - on a conceptual level.