Using Kotlin contracts to cast type inside Iterable function predicate
问题 I have this sealed class PictureEvent : sealed class PictureEvent { data class PictureCreated(val pictureId: String, val url: String) : PictureEvent() //more classes extending PictureEvent } Now, from a list of PictureEvent s, I want to get the first PictureCreated : fun doSomething(events: List<PictureEvent>) { val creationEvent = events.first { isCreationEvent(it) } as PictureEvent.PictureCreated //do stuff with the creationEvent } private fun isCreationEvent(event: PictureEvent) : Boolean