Do not create iterator in 'any', 'none', 'all' and 'count' unless necessary
#KT-19133 Fixed
This commit is contained in:
@@ -8880,72 +8880,63 @@ public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {
|
|||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun <T> Array<out T>.any(): Boolean {
|
public fun <T> Array<out T>.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun ByteArray.any(): Boolean {
|
public fun ByteArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun ShortArray.any(): Boolean {
|
public fun ShortArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun IntArray.any(): Boolean {
|
public fun IntArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun LongArray.any(): Boolean {
|
public fun LongArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun FloatArray.any(): Boolean {
|
public fun FloatArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun DoubleArray.any(): Boolean {
|
public fun DoubleArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun BooleanArray.any(): Boolean {
|
public fun BooleanArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun CharArray.any(): Boolean {
|
public fun CharArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10634,72 +10625,63 @@ public fun CharArray.minWith(comparator: Comparator<in Char>): Char? {
|
|||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun <T> Array<out T>.none(): Boolean {
|
public fun <T> Array<out T>.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun ByteArray.none(): Boolean {
|
public fun ByteArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun ShortArray.none(): Boolean {
|
public fun ShortArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun IntArray.none(): Boolean {
|
public fun IntArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun LongArray.none(): Boolean {
|
public fun LongArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun FloatArray.none(): Boolean {
|
public fun FloatArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun DoubleArray.none(): Boolean {
|
public fun DoubleArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun BooleanArray.none(): Boolean {
|
public fun BooleanArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun CharArray.none(): Boolean {
|
public fun CharArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1361,6 +1361,7 @@ public infix fun <T> Iterable<T>.union(other: Iterable<T>): Set<T> {
|
|||||||
* Returns `true` if all elements match the given [predicate].
|
* Returns `true` if all elements match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
|
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
|
for (element in this) if (!predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1369,14 +1370,15 @@ public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
|
|||||||
* Returns `true` if collection has at least one element.
|
* Returns `true` if collection has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun <T> Iterable<T>.any(): Boolean {
|
public fun <T> Iterable<T>.any(): Boolean {
|
||||||
for (element in this) return true
|
if (this is Collection) return !isEmpty()
|
||||||
return false
|
return iterator().hasNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if at least one element matches the given [predicate].
|
* Returns `true` if at least one element matches the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
|
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
|
||||||
|
if (this is Collection && isEmpty()) return false
|
||||||
for (element in this) if (predicate(element)) return true
|
for (element in this) if (predicate(element)) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -1385,6 +1387,7 @@ public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
|
|||||||
* Returns the number of elements in this collection.
|
* Returns the number of elements in this collection.
|
||||||
*/
|
*/
|
||||||
public fun <T> Iterable<T>.count(): Int {
|
public fun <T> Iterable<T>.count(): Int {
|
||||||
|
if (this is Collection) return size
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) count++
|
for (element in this) count++
|
||||||
return count
|
return count
|
||||||
@@ -1402,6 +1405,7 @@ public inline fun <T> Collection<T>.count(): Int {
|
|||||||
* Returns the number of elements matching the given [predicate].
|
* Returns the number of elements matching the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean): Int {
|
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean): Int {
|
||||||
|
if (this is Collection && isEmpty()) return 0
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) if (predicate(element)) count++
|
for (element in this) if (predicate(element)) count++
|
||||||
return count
|
return count
|
||||||
@@ -1653,14 +1657,15 @@ public fun <T> Iterable<T>.minWith(comparator: Comparator<in T>): T? {
|
|||||||
* Returns `true` if the collection has no elements.
|
* Returns `true` if the collection has no elements.
|
||||||
*/
|
*/
|
||||||
public fun <T> Iterable<T>.none(): Boolean {
|
public fun <T> Iterable<T>.none(): Boolean {
|
||||||
for (element in this) return false
|
if (this is Collection) return isEmpty()
|
||||||
return true
|
return !iterator().hasNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if no elements match the given [predicate].
|
* Returns `true` if no elements match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
|
public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
|
||||||
|
if (this is Collection && isEmpty()) return true
|
||||||
for (element in this) if (predicate(element)) return false
|
for (element in this) if (predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.mapTo(des
|
|||||||
* Returns `true` if all entries match the given [predicate].
|
* Returns `true` if all entries match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
||||||
|
if (isEmpty()) return true
|
||||||
for (element in this) if (!predicate(element)) return false
|
for (element in this) if (!predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -96,14 +97,14 @@ public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boole
|
|||||||
* Returns `true` if map has at least one entry.
|
* Returns `true` if map has at least one entry.
|
||||||
*/
|
*/
|
||||||
public fun <K, V> Map<out K, V>.any(): Boolean {
|
public fun <K, V> Map<out K, V>.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if at least one entry matches the given [predicate].
|
* Returns `true` if at least one entry matches the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
||||||
|
if (isEmpty()) return false
|
||||||
for (element in this) if (predicate(element)) return true
|
for (element in this) if (predicate(element)) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -120,6 +121,7 @@ public inline fun <K, V> Map<out K, V>.count(): Int {
|
|||||||
* Returns the number of entries matching the given [predicate].
|
* Returns the number of entries matching the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
|
public inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
|
||||||
|
if (isEmpty()) return 0
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) if (predicate(element)) count++
|
for (element in this) if (predicate(element)) count++
|
||||||
return count
|
return count
|
||||||
@@ -167,14 +169,14 @@ public fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V
|
|||||||
* Returns `true` if the map has no entries.
|
* Returns `true` if the map has no entries.
|
||||||
*/
|
*/
|
||||||
public fun <K, V> Map<out K, V>.none(): Boolean {
|
public fun <K, V> Map<out K, V>.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if no entries match the given [predicate].
|
* Returns `true` if no entries match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
||||||
|
if (isEmpty()) return true
|
||||||
for (element in this) if (predicate(element)) return false
|
for (element in this) if (predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -936,8 +936,7 @@ public inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean {
|
|||||||
* The operation is _terminal_.
|
* The operation is _terminal_.
|
||||||
*/
|
*/
|
||||||
public fun <T> Sequence<T>.any(): Boolean {
|
public fun <T> Sequence<T>.any(): Boolean {
|
||||||
for (element in this) return true
|
return iterator().hasNext()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1215,8 +1214,7 @@ public fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T? {
|
|||||||
* The operation is _terminal_.
|
* The operation is _terminal_.
|
||||||
*/
|
*/
|
||||||
public fun <T> Sequence<T>.none(): Boolean {
|
public fun <T> Sequence<T>.none(): Boolean {
|
||||||
for (element in this) return false
|
return !iterator().hasNext()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -815,8 +815,7 @@ public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
|
|||||||
* Returns `true` if char sequence has at least one character.
|
* Returns `true` if char sequence has at least one character.
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.any(): Boolean {
|
public fun CharSequence.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1003,8 +1002,7 @@ public fun CharSequence.minWith(comparator: Comparator<in Char>): Char? {
|
|||||||
* Returns `true` if the char sequence has no characters.
|
* Returns `true` if the char sequence has no characters.
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.none(): Boolean {
|
public fun CharSequence.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8950,72 +8950,63 @@ public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {
|
|||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun <T> Array<out T>.any(): Boolean {
|
public fun <T> Array<out T>.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun ByteArray.any(): Boolean {
|
public fun ByteArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun ShortArray.any(): Boolean {
|
public fun ShortArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun IntArray.any(): Boolean {
|
public fun IntArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun LongArray.any(): Boolean {
|
public fun LongArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun FloatArray.any(): Boolean {
|
public fun FloatArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun DoubleArray.any(): Boolean {
|
public fun DoubleArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun BooleanArray.any(): Boolean {
|
public fun BooleanArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if array has at least one element.
|
* Returns `true` if array has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun CharArray.any(): Boolean {
|
public fun CharArray.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10704,72 +10695,63 @@ public fun CharArray.minWith(comparator: Comparator<in Char>): Char? {
|
|||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun <T> Array<out T>.none(): Boolean {
|
public fun <T> Array<out T>.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun ByteArray.none(): Boolean {
|
public fun ByteArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun ShortArray.none(): Boolean {
|
public fun ShortArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun IntArray.none(): Boolean {
|
public fun IntArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun LongArray.none(): Boolean {
|
public fun LongArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun FloatArray.none(): Boolean {
|
public fun FloatArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun DoubleArray.none(): Boolean {
|
public fun DoubleArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun BooleanArray.none(): Boolean {
|
public fun BooleanArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if the array has no elements.
|
* Returns `true` if the array has no elements.
|
||||||
*/
|
*/
|
||||||
public fun CharArray.none(): Boolean {
|
public fun CharArray.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1371,6 +1371,7 @@ public infix fun <T> Iterable<T>.union(other: Iterable<T>): Set<T> {
|
|||||||
* Returns `true` if all elements match the given [predicate].
|
* Returns `true` if all elements match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
|
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
|
for (element in this) if (!predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1379,14 +1380,15 @@ public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
|
|||||||
* Returns `true` if collection has at least one element.
|
* Returns `true` if collection has at least one element.
|
||||||
*/
|
*/
|
||||||
public fun <T> Iterable<T>.any(): Boolean {
|
public fun <T> Iterable<T>.any(): Boolean {
|
||||||
for (element in this) return true
|
if (this is Collection) return !isEmpty()
|
||||||
return false
|
return iterator().hasNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if at least one element matches the given [predicate].
|
* Returns `true` if at least one element matches the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
|
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
|
||||||
|
if (this is Collection && isEmpty()) return false
|
||||||
for (element in this) if (predicate(element)) return true
|
for (element in this) if (predicate(element)) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -1395,6 +1397,7 @@ public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
|
|||||||
* Returns the number of elements in this collection.
|
* Returns the number of elements in this collection.
|
||||||
*/
|
*/
|
||||||
public fun <T> Iterable<T>.count(): Int {
|
public fun <T> Iterable<T>.count(): Int {
|
||||||
|
if (this is Collection) return size
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) count++
|
for (element in this) count++
|
||||||
return count
|
return count
|
||||||
@@ -1412,6 +1415,7 @@ public inline fun <T> Collection<T>.count(): Int {
|
|||||||
* Returns the number of elements matching the given [predicate].
|
* Returns the number of elements matching the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean): Int {
|
public inline fun <T> Iterable<T>.count(predicate: (T) -> Boolean): Int {
|
||||||
|
if (this is Collection && isEmpty()) return 0
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) if (predicate(element)) count++
|
for (element in this) if (predicate(element)) count++
|
||||||
return count
|
return count
|
||||||
@@ -1663,14 +1667,15 @@ public fun <T> Iterable<T>.minWith(comparator: Comparator<in T>): T? {
|
|||||||
* Returns `true` if the collection has no elements.
|
* Returns `true` if the collection has no elements.
|
||||||
*/
|
*/
|
||||||
public fun <T> Iterable<T>.none(): Boolean {
|
public fun <T> Iterable<T>.none(): Boolean {
|
||||||
for (element in this) return false
|
if (this is Collection) return isEmpty()
|
||||||
return true
|
return !iterator().hasNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if no elements match the given [predicate].
|
* Returns `true` if no elements match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
|
public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
|
||||||
|
if (this is Collection && isEmpty()) return true
|
||||||
for (element in this) if (predicate(element)) return false
|
for (element in this) if (predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.mapTo(des
|
|||||||
* Returns `true` if all entries match the given [predicate].
|
* Returns `true` if all entries match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
||||||
|
if (isEmpty()) return true
|
||||||
for (element in this) if (!predicate(element)) return false
|
for (element in this) if (!predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -96,14 +97,14 @@ public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boole
|
|||||||
* Returns `true` if map has at least one entry.
|
* Returns `true` if map has at least one entry.
|
||||||
*/
|
*/
|
||||||
public fun <K, V> Map<out K, V>.any(): Boolean {
|
public fun <K, V> Map<out K, V>.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if at least one entry matches the given [predicate].
|
* Returns `true` if at least one entry matches the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
||||||
|
if (isEmpty()) return false
|
||||||
for (element in this) if (predicate(element)) return true
|
for (element in this) if (predicate(element)) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -120,6 +121,7 @@ public inline fun <K, V> Map<out K, V>.count(): Int {
|
|||||||
* Returns the number of entries matching the given [predicate].
|
* Returns the number of entries matching the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
|
public inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
|
||||||
|
if (isEmpty()) return 0
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) if (predicate(element)) count++
|
for (element in this) if (predicate(element)) count++
|
||||||
return count
|
return count
|
||||||
@@ -167,14 +169,14 @@ public fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V
|
|||||||
* Returns `true` if the map has no entries.
|
* Returns `true` if the map has no entries.
|
||||||
*/
|
*/
|
||||||
public fun <K, V> Map<out K, V>.none(): Boolean {
|
public fun <K, V> Map<out K, V>.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if no entries match the given [predicate].
|
* Returns `true` if no entries match the given [predicate].
|
||||||
*/
|
*/
|
||||||
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
|
||||||
|
if (isEmpty()) return true
|
||||||
for (element in this) if (predicate(element)) return false
|
for (element in this) if (predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -958,8 +958,7 @@ public inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean {
|
|||||||
* The operation is _terminal_.
|
* The operation is _terminal_.
|
||||||
*/
|
*/
|
||||||
public fun <T> Sequence<T>.any(): Boolean {
|
public fun <T> Sequence<T>.any(): Boolean {
|
||||||
for (element in this) return true
|
return iterator().hasNext()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1237,8 +1236,7 @@ public fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T? {
|
|||||||
* The operation is _terminal_.
|
* The operation is _terminal_.
|
||||||
*/
|
*/
|
||||||
public fun <T> Sequence<T>.none(): Boolean {
|
public fun <T> Sequence<T>.none(): Boolean {
|
||||||
for (element in this) return false
|
return !iterator().hasNext()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -823,8 +823,7 @@ public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
|
|||||||
* Returns `true` if char sequence has at least one character.
|
* Returns `true` if char sequence has at least one character.
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.any(): Boolean {
|
public fun CharSequence.any(): Boolean {
|
||||||
for (element in this) return true
|
return !isEmpty()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1011,8 +1010,7 @@ public fun CharSequence.minWith(comparator: Comparator<in Char>): Char? {
|
|||||||
* Returns `true` if the char sequence has no characters.
|
* Returns `true` if the char sequence has no characters.
|
||||||
*/
|
*/
|
||||||
public fun CharSequence.none(): Boolean {
|
public fun CharSequence.none(): Boolean {
|
||||||
for (element in this) return false
|
return isEmpty()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,8 +10,13 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
inline(true)
|
inline(true)
|
||||||
doc { f -> "Returns `true` if all ${f.element.pluralize()} match the given [predicate]." }
|
doc { f -> "Returns `true` if all ${f.element.pluralize()} match the given [predicate]." }
|
||||||
returns("Boolean")
|
returns("Boolean")
|
||||||
body {
|
body { f ->
|
||||||
"""
|
"""
|
||||||
|
${when (f) {
|
||||||
|
Iterables -> "if (this is Collection && isEmpty()) return true"
|
||||||
|
Maps -> "if (isEmpty()) return true"
|
||||||
|
else -> ""
|
||||||
|
}}
|
||||||
for (element in this) if (!predicate(element)) return false
|
for (element in this) if (!predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
"""
|
"""
|
||||||
@@ -24,8 +29,13 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
|
|
||||||
doc { f -> "Returns `true` if no ${f.element.pluralize()} match the given [predicate]." }
|
doc { f -> "Returns `true` if no ${f.element.pluralize()} match the given [predicate]." }
|
||||||
returns("Boolean")
|
returns("Boolean")
|
||||||
body {
|
body { f ->
|
||||||
"""
|
"""
|
||||||
|
${when (f) {
|
||||||
|
Iterables -> "if (this is Collection && isEmpty()) return true"
|
||||||
|
Maps -> "if (isEmpty()) return true"
|
||||||
|
else -> ""
|
||||||
|
}}
|
||||||
for (element in this) if (predicate(element)) return false
|
for (element in this) if (predicate(element)) return false
|
||||||
return true
|
return true
|
||||||
"""
|
"""
|
||||||
@@ -37,11 +47,17 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
doc { f -> "Returns `true` if the ${f.collection} has no ${f.element.pluralize()}." }
|
doc { f -> "Returns `true` if the ${f.collection} has no ${f.element.pluralize()}." }
|
||||||
returns("Boolean")
|
returns("Boolean")
|
||||||
body {
|
body {
|
||||||
|
"return !iterator().hasNext()"
|
||||||
|
}
|
||||||
|
body(Iterables) {
|
||||||
"""
|
"""
|
||||||
for (element in this) return false
|
if (this is Collection) return isEmpty()
|
||||||
return true
|
return !iterator().hasNext()
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
body(Maps, CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||||
|
"return isEmpty()"
|
||||||
|
}
|
||||||
include(Maps, CharSequences)
|
include(Maps, CharSequences)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +66,13 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
|
|
||||||
doc { f -> "Returns `true` if at least one ${f.element} matches the given [predicate]." }
|
doc { f -> "Returns `true` if at least one ${f.element} matches the given [predicate]." }
|
||||||
returns("Boolean")
|
returns("Boolean")
|
||||||
body {
|
body { f ->
|
||||||
"""
|
"""
|
||||||
|
${when (f) {
|
||||||
|
Iterables -> "if (this is Collection && isEmpty()) return false"
|
||||||
|
Maps -> "if (isEmpty()) return false"
|
||||||
|
else -> ""
|
||||||
|
}}
|
||||||
for (element in this) if (predicate(element)) return true
|
for (element in this) if (predicate(element)) return true
|
||||||
return false
|
return false
|
||||||
"""
|
"""
|
||||||
@@ -63,11 +84,17 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
doc { f -> "Returns `true` if ${f.collection} has at least one ${f.element}." }
|
doc { f -> "Returns `true` if ${f.collection} has at least one ${f.element}." }
|
||||||
returns("Boolean")
|
returns("Boolean")
|
||||||
body {
|
body {
|
||||||
|
"return iterator().hasNext()"
|
||||||
|
}
|
||||||
|
body(Iterables) {
|
||||||
"""
|
"""
|
||||||
for (element in this) return true
|
if (this is Collection) return !isEmpty()
|
||||||
return false
|
return iterator().hasNext()
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
body(Maps, CharSequences, ArraysOfObjects, ArraysOfPrimitives) {
|
||||||
|
"return !isEmpty()"
|
||||||
|
}
|
||||||
include(Maps, CharSequences)
|
include(Maps, CharSequences)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,8 +103,13 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
|
|
||||||
doc { f -> "Returns the number of ${f.element.pluralize()} matching the given [predicate]." }
|
doc { f -> "Returns the number of ${f.element.pluralize()} matching the given [predicate]." }
|
||||||
returns("Int")
|
returns("Int")
|
||||||
body {
|
body { f ->
|
||||||
"""
|
"""
|
||||||
|
${when (f) {
|
||||||
|
Iterables -> "if (this is Collection && isEmpty()) return 0"
|
||||||
|
Maps -> "if (isEmpty()) return 0"
|
||||||
|
else -> ""
|
||||||
|
}}
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) if (predicate(element)) count++
|
for (element in this) if (predicate(element)) count++
|
||||||
return count
|
return count
|
||||||
@@ -89,8 +121,9 @@ fun aggregates(): List<GenericFunction> {
|
|||||||
templates add f("count()") {
|
templates add f("count()") {
|
||||||
doc { f -> "Returns the number of ${f.element.pluralize()} in this ${f.collection}." }
|
doc { f -> "Returns the number of ${f.element.pluralize()} in this ${f.collection}." }
|
||||||
returns("Int")
|
returns("Int")
|
||||||
body {
|
body { f ->
|
||||||
"""
|
"""
|
||||||
|
${if (f == Iterables) "if (this is Collection) return size" else "" }
|
||||||
var count = 0
|
var count = 0
|
||||||
for (element in this) count++
|
for (element in this) count++
|
||||||
return count
|
return count
|
||||||
|
|||||||
Reference in New Issue
Block a user