I’ve noticed that calling extensions such as .filterNotNull()
on a MutableList<> will return a normal (read: immutable) List<> instead of a MutableList<> as was called on. It seems that’s the documented behavior, but I think it would make more sense to retain mutability without having to call .toMutableList()
again. For example:
This doesn’t work today:
mutableListOf("test", null)
.filterNotNull()
.add("another test")
Instead it must be:
mutableListOf("test", null)
.filterNotNull()
.toMutableList()
.add("another test")
Are there other language design decisions at play here that provide reason for returning an immutable list from an extension run on a MutableIterable<>
?