Option 1:

inline fun <reified T, Y> MutableList<T>.listOfField(property: KMutableProperty1<T, Y?>): MutableList<Y> {
val yy = ArrayList<Y>()
this.forEach { t: T ->
yy.add(property.get(t) as Y)
return yy
val serviceIds = services.listOfField(ServiceModel::id)

Option 2:

var serviceIds: MutableList<String> = services.map { it.id }.toMutableList()

Option 3:

var serviceIds = services.map(Person::id)

Koin 2.0 — A pragmatic lightweight dependency injection framework for Kotlin

Anoop M Madasseri

Nothing great ever came that easy.!!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store