What is the difference between find and firstOrNull?

Viewed 16314

Given the following code extracted from 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) }
}

My own solution used customers.find. Both work in the koan scenario.

The documentation for firstOrNull and find seem to be very similar.

What is the difference between these two functions?

1 Answers
Related