gildor
06/14/2017, 9:36 AMfirst and get nonnull resultjasonlow
06/14/2017, 9:41 AMyou can use `first` and get nonnull resultjasonlow
06/14/2017, 9:42 AMjasonlow
06/14/2017, 9:46 AMgildor
06/14/2017, 9:46 AMvoddan
06/14/2017, 9:46 AMfindjasonlow
06/14/2017, 9:50 AMjasonlow
06/14/2017, 9:52 AMfirstOrNull and find?menegatti
06/14/2017, 9:54 AMfind will iterate the whole list trying to find the element that matches the predicatemenegatti
06/14/2017, 9:55 AMfirstOrNull won't, as it will return on the 1st element or null right awayjasonlow
06/14/2017, 10:04 AMfind is just wrapping around firstOrNull
/**
* Returns the first element matching the given [predicate], or `null` if no such element was found.
*/
@kotlin.internal.InlineOnly
public inline fun <T> Iterable<T>.find(predicate: (T) -> Boolean): T? {
return firstOrNull(predicate)
}menegatti
06/14/2017, 10:05 AMfirstOrNullmenegatti
06/14/2017, 10:06 AMmenegatti
06/14/2017, 10:06 AMmenegatti
06/14/2017, 10:06 AMmenegatti
06/14/2017, 10:07 AMfirstOrNull with a certain predicate, then it is the exact same thing as findgildor
06/14/2017, 10:08 AMsame thing asasfirstOrNull
first. first is just alias for firstOrNullmenegatti
06/14/2017, 10:10 AMvoddan
06/14/2017, 11:52 AMfind is used in other langs, but firstOrNull is more explicit and "kotlin way"voddan
06/14/2017, 11:52 AMfind is an alias to findOrNull (it is also shorter)voddan
06/14/2017, 11:53 AM