I am trying to create a function that returns Map<String, Int>, with the key being a specific tag and the value being the number of occurrences.
The object (simplified) from which I need to extract information:
class Note {
List<String> tags
}
Function so far:
private fun extractTags(notes: List<Note>): Map<String, Int> {
return notes.map { note -> note.tags }
.groupBy { it }
.mapValues { it.value.count() }
}
At the moment, the compiler is giving me a return type mismatch Map<(Mutable)Set<String!>!, Int>, and I'm not sure if I am getting the desired result (since I still cannot verify this correctly).
I expect the result in the lines:
(tag1, 1)
(tag2, 4)
(tag3, 14)
...
source
share