Skip to content
Advertisement

Map and groupBy values in a stream

I have a wrapper that may or may not contain data:

JavaScript

I group one user to multiple contacts:

JavaScript

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.

Advertisement

Answer

Does this work for you (first attempt at Kotlin) ?

JavaScript

Conceptually this requires another filter/exception handling for empty optional via toEmail. Similarly one of your methods could be simplified as

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement