August 2018
Beginner
178 pages
4h 56m
English
This function does the same job as the single, but instead of throwing an exception returns null if no or more than 1 item matches the predicate.
val numbers = listOf(1, 2, 3, 4, 5)val smallerThan1 = numbers.singleOrNull { n -> n < 1 }
Read now
Unlock full access