Eduardo Pinto
04/25/2019, 9:45 AM/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
if (this is Collection && isEmpty()) return true
for (element in this) if (!predicate(element)) return false
return true
}
Does this condition: if (this is Collection && isEmpty()) return true
makes sense? Should return true for applying a predicate to an empty collection?
Example:
val s = emptyList<String>()
if (s.all { it.isNotEmpty() }) {
// should the code enter here?
}
gildor
04/25/2019, 9:46 AMEduardo Pinto
04/25/2019, 9:57 AMEduardo Pinto
04/25/2019, 9:58 AMMarko Mitic
04/25/2019, 11:36 AMall
=== noneDont
Shawn
04/25/2019, 1:37 PMStephan Schroeder
04/26/2019, 10:07 AMEduardo Pinto
05/02/2019, 11:26 AMEduardo Pinto
05/02/2019, 11:27 AM