class Batch(val id: String, val filenames: MutableList<String>)val batchId = ...val batches = mutableMapOf<String, Batch>()val batch = batches.getOrPut(batchId, { Batch(id = batchId, filenames = mutableListOf())})batch.filenames.add("...")
The long version
val batch = batches[batchId] ?: let { val b = Batch(id = batchId, filenames = mutableListOf()) batches[batchId] = b b}