I spent far too long trying to work out how to pass a number of Migration instances to a Room database builder for a Dagger2 module.
The Room database builder requires context and the database name.
Room.databaseBuilder(context, Database::class.java, dbName)
.build()
Migrations can be added to the builder with the addMigrations method which takes vararg migrations: Migration!
One option is to create the builder.
val builder = Room.databaseBuilder(context, Database::class.java, dbName)
And then forEach through the migrations
migrations.forEach { builder.addMigrations(it) }
however this is messy and unnecessary, and the spread operator should be used instead.
I managed to miss this as the only documentation I found for the spread operator was a single sentence in the docs.
When we call a vararg-function, we can pass arguments one-by-one, e.g. asList(1, 2, 3), or, if we already have an array and want to pass its contents to the function, we use the spread operator (prefix the array with *)