I've been trying to make a function that returns a Map<String, Int>
with the key being a certain tag and the value being the number of occurrences.
The object (simplified) from which I need to extract the info:
class Note {
List<String> tags
}
The function so far:
private fun extractTags(notes: List<Note>): Map<String, Int> {
return notes.map { note -> note.tags }
.groupBy { it }
.mapValues { it.value.count() }
}
Right now the compiler gives me a return type mismatch of Map<(Mutable)Set<String!>!, Int>
and I'm not certain I'm getting the desired result (as I still can't test this properly).
I'm expecting a result something in the lines of:
(tag1, 1)
(tag2, 4)
(tag3, 14)
...