Hey Kotlin fam! I'm sure there must be a more effi...
# announcements
a
Hey Kotlin fam! I'm sure there must be a more efficient way to do this, can't quite think of what though... Determine whether a list of objects contains an object with a specified property value? Example (bad):
Copy code
data class Objects(
    val objects: List<MyObject>
) {

    fun containsFirstProperty(value: String): Boolean {
        var itDoes = false
        objects.forEach {
            if (it.firstProperty == value)
                itDoes = true
        }
        return itDoes
    }
}

data class MyObject(
    val firstProperty: String,
    val secondProperty: String
)
Thanks!
c
objects.any { it.firstProperty == value }
👍 4
a
EXACTLY! 🙂
a
I do this with an extension function on List, at least for your specific example that would be better than creating a whole Objects class.