due to if else statements
# announcements
c
due to if else statements
g
There is no standart syntax in kotlin for this, some people use something like
ifNonNull(type, events) { t,e -> t to e }
, but nothing in stdlib. There is discussion about this on Kotlin forum
Also you can use early return to avoid nullability, also this approach is more efficient
Copy code
data.mapNotNull {
    val json = it.asJsonObjectOrNull()
    val type = json?.get("type")?.asStringOrNull() ?: return@mapNotNull null
    val events = json?.get("events")?.asJsonArrayOrNull() ?: return@mapNotNull null

    type to events
}.toMap()
c
This is looking promising and fast Thanks @gildor