I was writing a small piece of code in which I internally handle my data in a mutable map, which in turn has mutable lists.
I wanted to expose my data to the API use
A classic solution is to copy your data, so that even if modified, the change would not affect the private class property:
class School { private val roster = mutableMapOf>() fun db(): Map> = roster.mapValuestTo {it.value.toList} }