Kotlin 中是否有与Scala 的 Traversable.collect函数等效的函数?
具体来说,我想将一个列表映射到一个列表,但前提是能够成功。
myList.map {
val myNullableThing = it.someNullableMethod()
// If it is null, then I cannot continue here
// and I want to simply ignore this item
}
Run Code Online (Sandbox Code Playgroud)
虽然不如 Scalacollect函数那么通用,mapNotNull但应该适用于您的情况:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map-not-null.html
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |