鉴于从Kotlin Koans中提取的以下代码:
fun Shop.findAnyCustomerFrom(city: City): Customer? {
// Return a customer who lives in the given city, or null if there is none
return customers.firstOrNull { it.isFrom(city) }
}
Run Code Online (Sandbox Code Playgroud)
我用自己的解决方案customers.find.两者都在koan场景中工作.
文档firstOrNull和find似乎非常相似.
这两个功能有什么区别?