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 }
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 }
3.144.48.218