Add samples for any, all and none

Rewrite samples to make them working on sample generator

Move location of the class that contains samples of Aggregates.kt
This commit is contained in:
Yuta Sakata
2018-02-15 21:02:47 +09:00
committed by Ilya Gorbunov
parent a2897a29b5
commit 4926b5a4c0
17 changed files with 480 additions and 5 deletions
@@ -9491,6 +9491,8 @@ public infix fun CharArray.union(other: Iterable<Char>): Set<Char> {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9499,6 +9501,8 @@ public inline fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9507,6 +9511,8 @@ public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9515,6 +9521,8 @@ public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9523,6 +9531,8 @@ public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9531,6 +9541,8 @@ public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9539,6 +9551,8 @@ public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9547,6 +9561,8 @@ public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9555,6 +9571,8 @@ public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9563,6 +9581,8 @@ public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun <T> Array<out T>.any(): Boolean {
return !isEmpty()
@@ -9570,6 +9590,8 @@ public fun <T> Array<out T>.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun ByteArray.any(): Boolean {
return !isEmpty()
@@ -9577,6 +9599,8 @@ public fun ByteArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun ShortArray.any(): Boolean {
return !isEmpty()
@@ -9584,6 +9608,8 @@ public fun ShortArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun IntArray.any(): Boolean {
return !isEmpty()
@@ -9591,6 +9617,8 @@ public fun IntArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun LongArray.any(): Boolean {
return !isEmpty()
@@ -9598,6 +9626,8 @@ public fun LongArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun FloatArray.any(): Boolean {
return !isEmpty()
@@ -9605,6 +9635,8 @@ public fun FloatArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun DoubleArray.any(): Boolean {
return !isEmpty()
@@ -9612,6 +9644,8 @@ public fun DoubleArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun BooleanArray.any(): Boolean {
return !isEmpty()
@@ -9619,6 +9653,8 @@ public fun BooleanArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun CharArray.any(): Boolean {
return !isEmpty()
@@ -9626,6 +9662,8 @@ public fun CharArray.any(): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun <T> Array<out T>.any(predicate: (T) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9634,6 +9672,8 @@ public inline fun <T> Array<out T>.any(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun ByteArray.any(predicate: (Byte) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9642,6 +9682,8 @@ public inline fun ByteArray.any(predicate: (Byte) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun ShortArray.any(predicate: (Short) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9650,6 +9692,8 @@ public inline fun ShortArray.any(predicate: (Short) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun IntArray.any(predicate: (Int) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9658,6 +9702,8 @@ public inline fun IntArray.any(predicate: (Int) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun LongArray.any(predicate: (Long) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9666,6 +9712,8 @@ public inline fun LongArray.any(predicate: (Long) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun FloatArray.any(predicate: (Float) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9674,6 +9722,8 @@ public inline fun FloatArray.any(predicate: (Float) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun DoubleArray.any(predicate: (Double) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9682,6 +9732,8 @@ public inline fun DoubleArray.any(predicate: (Double) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun BooleanArray.any(predicate: (Boolean) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -9690,6 +9742,8 @@ public inline fun BooleanArray.any(predicate: (Boolean) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun CharArray.any(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -11308,6 +11362,8 @@ public fun CharArray.minWith(comparator: Comparator<in Char>): Char? {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun <T> Array<out T>.none(): Boolean {
return isEmpty()
@@ -11315,6 +11371,8 @@ public fun <T> Array<out T>.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun ByteArray.none(): Boolean {
return isEmpty()
@@ -11322,6 +11380,8 @@ public fun ByteArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun ShortArray.none(): Boolean {
return isEmpty()
@@ -11329,6 +11389,8 @@ public fun ShortArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun IntArray.none(): Boolean {
return isEmpty()
@@ -11336,6 +11398,8 @@ public fun IntArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun LongArray.none(): Boolean {
return isEmpty()
@@ -11343,6 +11407,8 @@ public fun LongArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun FloatArray.none(): Boolean {
return isEmpty()
@@ -11350,6 +11416,8 @@ public fun FloatArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun DoubleArray.none(): Boolean {
return isEmpty()
@@ -11357,6 +11425,8 @@ public fun DoubleArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun BooleanArray.none(): Boolean {
return isEmpty()
@@ -11364,6 +11434,8 @@ public fun BooleanArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun CharArray.none(): Boolean {
return isEmpty()
@@ -11371,6 +11443,8 @@ public fun CharArray.none(): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun <T> Array<out T>.none(predicate: (T) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11379,6 +11453,8 @@ public inline fun <T> Array<out T>.none(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun ByteArray.none(predicate: (Byte) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11387,6 +11463,8 @@ public inline fun ByteArray.none(predicate: (Byte) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun ShortArray.none(predicate: (Short) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11395,6 +11473,8 @@ public inline fun ShortArray.none(predicate: (Short) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun IntArray.none(predicate: (Int) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11403,6 +11483,8 @@ public inline fun IntArray.none(predicate: (Int) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun LongArray.none(predicate: (Long) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11411,6 +11493,8 @@ public inline fun LongArray.none(predicate: (Long) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun FloatArray.none(predicate: (Float) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11419,6 +11503,8 @@ public inline fun FloatArray.none(predicate: (Float) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun DoubleArray.none(predicate: (Double) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11427,6 +11513,8 @@ public inline fun DoubleArray.none(predicate: (Double) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun BooleanArray.none(predicate: (Boolean) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11435,6 +11523,8 @@ public inline fun BooleanArray.none(predicate: (Boolean) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun CharArray.none(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -1359,6 +1359,8 @@ public infix fun <T> Iterable<T>.union(other: Iterable<T>): Set<T> {
/**
* 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
@@ -1368,6 +1370,8 @@ public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if collection has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun <T> Iterable<T>.any(): Boolean {
if (this is Collection) return !isEmpty()
@@ -1376,6 +1380,8 @@ public fun <T> Iterable<T>.any(): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
if (this is Collection && isEmpty()) return false
@@ -1655,6 +1661,8 @@ public fun <T> Iterable<T>.minWith(comparator: Comparator<in T>): T? {
/**
* Returns `true` if the collection has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun <T> Iterable<T>.none(): Boolean {
if (this is Collection) return isEmpty()
@@ -1663,6 +1671,8 @@ public fun <T> Iterable<T>.none(): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
if (this is Collection && isEmpty()) return true
@@ -86,6 +86,8 @@ 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].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return true
@@ -95,6 +97,8 @@ 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.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun <K, V> Map<out K, V>.any(): Boolean {
return !isEmpty()
@@ -102,6 +106,8 @@ public fun <K, V> Map<out K, V>.any(): Boolean {
/**
* Returns `true` if at least one entry matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return false
@@ -167,6 +173,8 @@ public fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V
/**
* Returns `true` if the map has no entries.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun <K, V> Map<out K, V>.none(): Boolean {
return isEmpty()
@@ -174,6 +182,8 @@ public fun <K, V> Map<out K, V>.none(): Boolean {
/**
* Returns `true` if no entries match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return true
@@ -922,6 +922,8 @@ public fun <T> Sequence<T>.toMutableSet(): MutableSet<T> {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*
* The operation is _terminal_.
*/
@@ -932,6 +934,8 @@ public inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if sequence has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*
* The operation is _terminal_.
*/
@@ -941,6 +945,8 @@ public fun <T> Sequence<T>.any(): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*
* The operation is _terminal_.
*/
@@ -1210,6 +1216,8 @@ public fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T? {
/**
* Returns `true` if the sequence has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*
* The operation is _terminal_.
*/
@@ -1219,6 +1227,8 @@ public fun <T> Sequence<T>.none(): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*
* The operation is _terminal_.
*/
@@ -805,6 +805,8 @@ public fun CharSequence.withIndex(): Iterable<IndexedValue<Char>> {
/**
* Returns `true` if all characters match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -813,6 +815,8 @@ public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
/**
* Returns `true` if char sequence has at least one character.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun CharSequence.any(): Boolean {
return !isEmpty()
@@ -820,6 +824,8 @@ public fun CharSequence.any(): Boolean {
/**
* Returns `true` if at least one character matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun CharSequence.any(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -1000,6 +1006,8 @@ public fun CharSequence.minWith(comparator: Comparator<in Char>): Char? {
/**
* Returns `true` if the char sequence has no characters.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun CharSequence.none(): Boolean {
return isEmpty()
@@ -1007,6 +1015,8 @@ public fun CharSequence.none(): Boolean {
/**
* Returns `true` if no characters match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun CharSequence.none(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -5611,136 +5611,190 @@ public expect infix fun CharArray.union(other: Iterable<Char>): Set<Char>
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun <T> Array<out T>.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun ByteArray.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun ShortArray.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun IntArray.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun LongArray.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun FloatArray.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun DoubleArray.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun BooleanArray.any(): Boolean
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun CharArray.any(): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun <T> Array<out T>.any(predicate: (T) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun ByteArray.any(predicate: (Byte) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun ShortArray.any(predicate: (Short) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun IntArray.any(predicate: (Int) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun LongArray.any(predicate: (Long) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun FloatArray.any(predicate: (Float) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun DoubleArray.any(predicate: (Double) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun BooleanArray.any(predicate: (Boolean) -> Boolean): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun CharArray.any(predicate: (Char) -> Boolean): Boolean
@@ -6487,91 +6541,127 @@ public expect fun CharArray.minWith(comparator: Comparator<in Char>): Char?
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun <T> Array<out T>.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun ByteArray.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun ShortArray.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun IntArray.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun LongArray.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun FloatArray.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun DoubleArray.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun BooleanArray.none(): Boolean
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun CharArray.none(): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun <T> Array<out T>.none(predicate: (T) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun ByteArray.none(predicate: (Byte) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun ShortArray.none(predicate: (Short) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun IntArray.none(predicate: (Int) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun LongArray.none(predicate: (Long) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun FloatArray.none(predicate: (Float) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun DoubleArray.none(predicate: (Double) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun BooleanArray.none(predicate: (Boolean) -> Boolean): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun CharArray.none(predicate: (Char) -> Boolean): Boolean
@@ -706,16 +706,22 @@ public expect infix fun <T> Iterable<T>.union(other: Iterable<T>): Set<T>
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean
/**
* Returns `true` if collection has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun <T> Iterable<T>.any(): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean
@@ -838,11 +844,15 @@ public expect fun <T> Iterable<T>.minWith(comparator: Comparator<in T>): T?
/**
* Returns `true` if the collection has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun <T> Iterable<T>.none(): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean
@@ -51,16 +51,22 @@ public expect inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.ma
/**
* Returns `true` if all entries match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean
/**
* Returns `true` if map has at least one entry.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun <K, V> Map<out K, V>.any(): Boolean
/**
* Returns `true` if at least one entry matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean
@@ -105,11 +111,15 @@ public expect fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Ent
/**
* Returns `true` if the map has no entries.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun <K, V> Map<out K, V>.none(): Boolean
/**
* Returns `true` if no entries match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean
@@ -596,6 +596,8 @@ public expect fun <T> Sequence<T>.toMutableSet(): MutableSet<T>
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*
* The operation is _terminal_.
*/
@@ -603,6 +605,8 @@ public expect inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean
/**
* Returns `true` if sequence has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*
* The operation is _terminal_.
*/
@@ -610,6 +614,8 @@ public expect fun <T> Sequence<T>.any(): Boolean
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*
* The operation is _terminal_.
*/
@@ -746,6 +752,8 @@ public expect fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T?
/**
* Returns `true` if the sequence has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*
* The operation is _terminal_.
*/
@@ -753,6 +761,8 @@ public expect fun <T> Sequence<T>.none(): Boolean
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*
* The operation is _terminal_.
*/
@@ -494,16 +494,22 @@ public expect fun CharSequence.withIndex(): Iterable<IndexedValue<Char>>
/**
* Returns `true` if all characters match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public expect inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean
/**
* Returns `true` if char sequence has at least one character.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public expect fun CharSequence.any(): Boolean
/**
* Returns `true` if at least one character matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public expect inline fun CharSequence.any(predicate: (Char) -> Boolean): Boolean
@@ -588,11 +594,15 @@ public expect fun CharSequence.minWith(comparator: Comparator<in Char>): Char?
/**
* Returns `true` if the char sequence has no characters.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public expect fun CharSequence.none(): Boolean
/**
* Returns `true` if no characters match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public expect inline fun CharSequence.none(predicate: (Char) -> Boolean): Boolean
@@ -360,4 +360,59 @@ class Collections {
}
}
class Aggregates {
@Sample
fun all() {
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
assertFalse(zeroToTen.all { isEven(it) })
assertFalse(zeroToTen.all(isEven))
val evens = zeroToTen.map { it * 2 }
assertTrue(evens.all { isEven(it) })
assertTrue(emptyList<Int>().all { false })
}
@Sample
fun none() {
assertTrue(emptyList<Int>().none())
assertFalse(listOf("one", "two", "three").none())
}
@Sample
fun noneWithPredicate() {
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
assertFalse(zeroToTen.none { isEven(it) })
assertFalse(zeroToTen.none(isEven))
val odds = zeroToTen.map { it * 2 + 1 }
assertTrue(odds.none { isEven(it) })
assertTrue(emptyList<Int>().none { true })
}
@Sample
fun any() {
assertFalse(emptyList<Int>().any())
assertTrue(listOf(1, 2, 3).any())
}
@Sample
fun anyWithPredicate() {
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
assertTrue(zeroToTen.any { isEven(it) })
assertTrue(zeroToTen.any(isEven))
val odds = zeroToTen.map { it * 2 + 1 }
assertFalse(odds.any { isEven(it) })
assertFalse(emptyList<Int>().any { true })
}
}
}
+90
View File
@@ -9927,6 +9927,8 @@ public infix fun CharArray.union(other: Iterable<Char>): Set<Char> {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9935,6 +9937,8 @@ public inline fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9943,6 +9947,8 @@ public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9951,6 +9957,8 @@ public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9959,6 +9967,8 @@ public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9967,6 +9977,8 @@ public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9975,6 +9987,8 @@ public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9983,6 +9997,8 @@ public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9991,6 +10007,8 @@ public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -9999,6 +10017,8 @@ public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun <T> Array<out T>.any(): Boolean {
return !isEmpty()
@@ -10006,6 +10026,8 @@ public fun <T> Array<out T>.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun ByteArray.any(): Boolean {
return !isEmpty()
@@ -10013,6 +10035,8 @@ public fun ByteArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun ShortArray.any(): Boolean {
return !isEmpty()
@@ -10020,6 +10044,8 @@ public fun ShortArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun IntArray.any(): Boolean {
return !isEmpty()
@@ -10027,6 +10053,8 @@ public fun IntArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun LongArray.any(): Boolean {
return !isEmpty()
@@ -10034,6 +10062,8 @@ public fun LongArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun FloatArray.any(): Boolean {
return !isEmpty()
@@ -10041,6 +10071,8 @@ public fun FloatArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun DoubleArray.any(): Boolean {
return !isEmpty()
@@ -10048,6 +10080,8 @@ public fun DoubleArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun BooleanArray.any(): Boolean {
return !isEmpty()
@@ -10055,6 +10089,8 @@ public fun BooleanArray.any(): Boolean {
/**
* Returns `true` if array has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun CharArray.any(): Boolean {
return !isEmpty()
@@ -10062,6 +10098,8 @@ public fun CharArray.any(): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun <T> Array<out T>.any(predicate: (T) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10070,6 +10108,8 @@ public inline fun <T> Array<out T>.any(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun ByteArray.any(predicate: (Byte) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10078,6 +10118,8 @@ public inline fun ByteArray.any(predicate: (Byte) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun ShortArray.any(predicate: (Short) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10086,6 +10128,8 @@ public inline fun ShortArray.any(predicate: (Short) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun IntArray.any(predicate: (Int) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10094,6 +10138,8 @@ public inline fun IntArray.any(predicate: (Int) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun LongArray.any(predicate: (Long) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10102,6 +10148,8 @@ public inline fun LongArray.any(predicate: (Long) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun FloatArray.any(predicate: (Float) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10110,6 +10158,8 @@ public inline fun FloatArray.any(predicate: (Float) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun DoubleArray.any(predicate: (Double) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10118,6 +10168,8 @@ public inline fun DoubleArray.any(predicate: (Double) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun BooleanArray.any(predicate: (Boolean) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -10126,6 +10178,8 @@ public inline fun BooleanArray.any(predicate: (Boolean) -> Boolean): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun CharArray.any(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -11744,6 +11798,8 @@ public fun CharArray.minWith(comparator: Comparator<in Char>): Char? {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun <T> Array<out T>.none(): Boolean {
return isEmpty()
@@ -11751,6 +11807,8 @@ public fun <T> Array<out T>.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun ByteArray.none(): Boolean {
return isEmpty()
@@ -11758,6 +11816,8 @@ public fun ByteArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun ShortArray.none(): Boolean {
return isEmpty()
@@ -11765,6 +11825,8 @@ public fun ShortArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun IntArray.none(): Boolean {
return isEmpty()
@@ -11772,6 +11834,8 @@ public fun IntArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun LongArray.none(): Boolean {
return isEmpty()
@@ -11779,6 +11843,8 @@ public fun LongArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun FloatArray.none(): Boolean {
return isEmpty()
@@ -11786,6 +11852,8 @@ public fun FloatArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun DoubleArray.none(): Boolean {
return isEmpty()
@@ -11793,6 +11861,8 @@ public fun DoubleArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun BooleanArray.none(): Boolean {
return isEmpty()
@@ -11800,6 +11870,8 @@ public fun BooleanArray.none(): Boolean {
/**
* Returns `true` if the array has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun CharArray.none(): Boolean {
return isEmpty()
@@ -11807,6 +11879,8 @@ public fun CharArray.none(): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun <T> Array<out T>.none(predicate: (T) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11815,6 +11889,8 @@ public inline fun <T> Array<out T>.none(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun ByteArray.none(predicate: (Byte) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11823,6 +11899,8 @@ public inline fun ByteArray.none(predicate: (Byte) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun ShortArray.none(predicate: (Short) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11831,6 +11909,8 @@ public inline fun ShortArray.none(predicate: (Short) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun IntArray.none(predicate: (Int) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11839,6 +11919,8 @@ public inline fun IntArray.none(predicate: (Int) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun LongArray.none(predicate: (Long) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11847,6 +11929,8 @@ public inline fun LongArray.none(predicate: (Long) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun FloatArray.none(predicate: (Float) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11855,6 +11939,8 @@ public inline fun FloatArray.none(predicate: (Float) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun DoubleArray.none(predicate: (Double) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11863,6 +11949,8 @@ public inline fun DoubleArray.none(predicate: (Double) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun BooleanArray.none(predicate: (Boolean) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -11871,6 +11959,8 @@ public inline fun BooleanArray.none(predicate: (Boolean) -> Boolean): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun CharArray.none(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -1383,6 +1383,8 @@ public infix fun <T> Iterable<T>.union(other: Iterable<T>): Set<T> {
/**
* 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
@@ -1392,6 +1394,8 @@ public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if collection has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun <T> Iterable<T>.any(): Boolean {
if (this is Collection) return !isEmpty()
@@ -1400,6 +1404,8 @@ public fun <T> Iterable<T>.any(): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
if (this is Collection && isEmpty()) return false
@@ -1679,6 +1685,8 @@ public fun <T> Iterable<T>.minWith(comparator: Comparator<in T>): T? {
/**
* Returns `true` if the collection has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun <T> Iterable<T>.none(): Boolean {
if (this is Collection) return isEmpty()
@@ -1687,6 +1695,8 @@ public fun <T> Iterable<T>.none(): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean {
if (this is Collection && isEmpty()) return true
+10
View File
@@ -86,6 +86,8 @@ 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].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return true
@@ -95,6 +97,8 @@ 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.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun <K, V> Map<out K, V>.any(): Boolean {
return !isEmpty()
@@ -102,6 +106,8 @@ public fun <K, V> Map<out K, V>.any(): Boolean {
/**
* Returns `true` if at least one entry matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun <K, V> Map<out K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return false
@@ -167,6 +173,8 @@ public fun <K, V> Map<out K, V>.minWith(comparator: Comparator<in Map.Entry<K, V
/**
* Returns `true` if the map has no entries.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun <K, V> Map<out K, V>.none(): Boolean {
return isEmpty()
@@ -174,6 +182,8 @@ public fun <K, V> Map<out K, V>.none(): Boolean {
/**
* Returns `true` if no entries match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun <K, V> Map<out K, V>.none(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
if (isEmpty()) return true
@@ -963,6 +963,8 @@ public fun <T> Sequence<T>.toMutableSet(): MutableSet<T> {
/**
* Returns `true` if all elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*
* The operation is _terminal_.
*/
@@ -973,6 +975,8 @@ public inline fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean {
/**
* Returns `true` if sequence has at least one element.
*
* @sample samples.collections.Collections.Aggregates.any
*
* The operation is _terminal_.
*/
@@ -982,6 +986,8 @@ public fun <T> Sequence<T>.any(): Boolean {
/**
* Returns `true` if at least one element matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*
* The operation is _terminal_.
*/
@@ -1251,6 +1257,8 @@ public fun <T> Sequence<T>.minWith(comparator: Comparator<in T>): T? {
/**
* Returns `true` if the sequence has no elements.
*
* @sample samples.collections.Collections.Aggregates.none
*
* The operation is _terminal_.
*/
@@ -1260,6 +1268,8 @@ public fun <T> Sequence<T>.none(): Boolean {
/**
* Returns `true` if no elements match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*
* The operation is _terminal_.
*/
@@ -812,6 +812,8 @@ public fun CharSequence.withIndex(): Iterable<IndexedValue<Char>> {
/**
* Returns `true` if all characters match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (!predicate(element)) return false
@@ -820,6 +822,8 @@ public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
/**
* Returns `true` if char sequence has at least one character.
*
* @sample samples.collections.Collections.Aggregates.any
*/
public fun CharSequence.any(): Boolean {
return !isEmpty()
@@ -827,6 +831,8 @@ public fun CharSequence.any(): Boolean {
/**
* Returns `true` if at least one character matches the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.anyWithPredicate
*/
public inline fun CharSequence.any(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return true
@@ -1007,6 +1013,8 @@ public fun CharSequence.minWith(comparator: Comparator<in Char>): Char? {
/**
* Returns `true` if the char sequence has no characters.
*
* @sample samples.collections.Collections.Aggregates.none
*/
public fun CharSequence.none(): Boolean {
return isEmpty()
@@ -1014,6 +1022,8 @@ public fun CharSequence.none(): Boolean {
/**
* Returns `true` if no characters match the given [predicate].
*
* @sample samples.collections.Collections.Aggregates.noneWithPredicate
*/
public inline fun CharSequence.none(predicate: (Char) -> Boolean): Boolean {
for (element in this) if (predicate(element)) return false
@@ -34,7 +34,13 @@ object Aggregates : TemplateGroupBase() {
include(Maps, CharSequences)
} builder {
inline()
doc { "Returns `true` if all ${f.element.pluralize()} match the given [predicate]." }
doc {
"""
Returns `true` if all ${f.element.pluralize()} match the given [predicate].
@sample samples.collections.Collections.Aggregates.all
"""
}
returns("Boolean")
body {
"""
@@ -55,7 +61,13 @@ object Aggregates : TemplateGroupBase() {
} builder {
inline()
doc { "Returns `true` if no ${f.element.pluralize()} match the given [predicate]." }
doc {
"""
Returns `true` if no ${f.element.pluralize()} match the given [predicate].
@sample samples.collections.Collections.Aggregates.noneWithPredicate
"""
}
returns("Boolean")
body {
"""
@@ -74,7 +86,13 @@ object Aggregates : TemplateGroupBase() {
includeDefault()
include(Maps, CharSequences)
} builder {
doc { "Returns `true` if the ${f.collection} has no ${f.element.pluralize()}." }
doc {
"""
Returns `true` if the ${f.collection} has no ${f.element.pluralize()}.
@sample samples.collections.Collections.Aggregates.none
"""
}
returns("Boolean")
body {
"return !iterator().hasNext()"
@@ -98,7 +116,13 @@ object Aggregates : TemplateGroupBase() {
} builder {
inline()
doc { "Returns `true` if at least one ${f.element} matches the given [predicate]." }
doc {
"""
Returns `true` if at least one ${f.element} matches the given [predicate].
@sample samples.collections.Collections.Aggregates.anyWithPredicate
"""
}
returns("Boolean")
body {
"""
@@ -117,7 +141,13 @@ object Aggregates : TemplateGroupBase() {
includeDefault()
include(Maps, CharSequences)
} builder {
doc { "Returns `true` if ${f.collection} has at least one ${f.element}." }
doc {
"""
Returns `true` if ${f.collection} has at least one ${f.element}.
@sample samples.collections.Collections.Aggregates.any
"""
}
returns("Boolean")
body {
"return iterator().hasNext()"