lee.crawford
01/21/2023, 6:47 PMclass Nesting (val parent: Nesting? = null) {
val map = mutableMapOf("id" to nextId ())
override fun toString(): String = "${map["id"]}"
companion object {
private var count = 0
fun nextId () = count ++
}
}
fun main () {
val a = Nesting (Nesting (Nesting ()))
println (a.map)
println (a.parent?.map.get ("id") ?: "?")
}
ephemient
01/21/2023, 6:48 PM?.
works differently (and more usefully, IMO) in Kotlin than in Swift or Rusta?.b
is equivalent to if (a != null) a.b else null
something?.let { listOf(it) }.orEmpty()
where .orEmpty()
works even if the receiver is null
CLOVIS
01/22/2023, 1:24 PMa?.b
in Rust is written (a ?: return null).b
in Kotlin.bind
in the #arrow libraryephemient
01/22/2023, 3:02 PM?.
behavior can be achieved by using ?.
instead of .
everywhere downstream of the nullableRob Elliot
01/23/2023, 10:09 AM