I have a custom implementation of a list which returns a new item if none is contained within it.
@Parcelize
class ListOfItems(private val list: Map<String, Item> = mapOf()) : Parcelable {
operator fun get(name: String) = list[name] ?: Item(name)
}
I'd like to use it inside for loop:
val myListOfItems = ListOfItems(/* ... */)
for (item in myListOfItems)
{
// Do something...
}
How can I achieve it? Is there some interface that I have to implement o some method that I have to add?