mutate All Not Null
Applies transform to each element in the collection, removing the item if null
is returned.
The mutable equivalent to Collection.mapNotNull.
Note: this function removes in-place only if A is a MutableList, otherwise it clears the collection and re-adds the values.
Applies transform to each element in the list, removing the item if null
is returned.
The mutable equivalent to List.mapNotNull.
val p = Person(name = "John", job = Job("Developer", listOf("Kotlin", "Training")))
val newP = p.copy { // mutates the job.teams collection in-place
job.teams.mutateAllNotNull { it.takeUnless { it.startsWith("admin-") } }
}
Content copied to clipboard