对于斯卡拉氏Traversable.collect函数,Kotlin中是否有等价的?
具体来说,我想把一个列表映射到一个列表中,但前提是这样做可以成功。
myList.map {
val myNullableThing = it.someNullableMethod()
// If it is null, then I cannot continue here
// and I want to simply ignore this item
}发布于 2018-10-18 13:59:27
虽然比Scala collect函数更不通用,但在您的情况下,mapNotNull应该可以工作:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map-not-null.html
https://stackoverflow.com/questions/52875060
复制相似问题