From 4926b5a4c00c731c2391b34a89876c8636d24285 Mon Sep 17 00:00:00 2001 From: Yuta Sakata Date: Thu, 15 Feb 2018 21:02:47 +0900 Subject: [PATCH] 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 --- .../src/core/generated/_ArraysJs.kt | 90 +++++++++++++++++++ .../src/core/generated/_CollectionsJs.kt | 10 +++ js/js.libraries/src/core/generated/_MapsJs.kt | 10 +++ .../src/core/generated/_SequencesJs.kt | 10 +++ .../src/core/generated/_StringsJs.kt | 10 +++ .../stdlib/common/src/generated/_Arrays.kt | 90 +++++++++++++++++++ .../common/src/generated/_Collections.kt | 10 +++ .../stdlib/common/src/generated/_Maps.kt | 10 +++ .../stdlib/common/src/generated/_Sequences.kt | 10 +++ .../stdlib/common/src/generated/_Strings.kt | 10 +++ .../test/samples/collections/collections.kt | 55 ++++++++++++ libraries/stdlib/src/generated/_Arrays.kt | 90 +++++++++++++++++++ .../stdlib/src/generated/_Collections.kt | 10 +++ libraries/stdlib/src/generated/_Maps.kt | 10 +++ libraries/stdlib/src/generated/_Sequences.kt | 10 +++ libraries/stdlib/src/generated/_Strings.kt | 10 +++ .../src/templates/Aggregates.kt | 40 +++++++-- 17 files changed, 480 insertions(+), 5 deletions(-) diff --git a/js/js.libraries/src/core/generated/_ArraysJs.kt b/js/js.libraries/src/core/generated/_ArraysJs.kt index 8a38b6fb6e8..8e95a9efe15 100644 --- a/js/js.libraries/src/core/generated/_ArraysJs.kt +++ b/js/js.libraries/src/core/generated/_ArraysJs.kt @@ -9491,6 +9491,8 @@ public infix fun CharArray.union(other: Iterable): Set { /** * Returns `true` if all elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public inline fun Array.all(predicate: (T) -> Boolean): Boolean { for (element in this) if (!predicate(element)) return false @@ -9499,6 +9501,8 @@ public inline fun Array.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 Array.any(): Boolean { return !isEmpty() @@ -9570,6 +9590,8 @@ public fun Array.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 Array.any(predicate: (T) -> Boolean): Boolean { for (element in this) if (predicate(element)) return true @@ -9634,6 +9672,8 @@ public inline fun Array.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): Char? { /** * Returns `true` if the array has no elements. + * + * @sample samples.collections.Collections.Aggregates.none */ public fun Array.none(): Boolean { return isEmpty() @@ -11315,6 +11371,8 @@ public fun Array.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 Array.none(predicate: (T) -> Boolean): Boolean { for (element in this) if (predicate(element)) return false @@ -11379,6 +11453,8 @@ public inline fun Array.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 diff --git a/js/js.libraries/src/core/generated/_CollectionsJs.kt b/js/js.libraries/src/core/generated/_CollectionsJs.kt index 4735d194b34..c4c4581b433 100644 --- a/js/js.libraries/src/core/generated/_CollectionsJs.kt +++ b/js/js.libraries/src/core/generated/_CollectionsJs.kt @@ -1359,6 +1359,8 @@ public infix fun Iterable.union(other: Iterable): Set { /** * Returns `true` if all elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public inline fun Iterable.all(predicate: (T) -> Boolean): Boolean { if (this is Collection && isEmpty()) return true @@ -1368,6 +1370,8 @@ public inline fun Iterable.all(predicate: (T) -> Boolean): Boolean { /** * Returns `true` if collection has at least one element. + * + * @sample samples.collections.Collections.Aggregates.any */ public fun Iterable.any(): Boolean { if (this is Collection) return !isEmpty() @@ -1376,6 +1380,8 @@ public fun Iterable.any(): Boolean { /** * Returns `true` if at least one element matches the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.anyWithPredicate */ public inline fun Iterable.any(predicate: (T) -> Boolean): Boolean { if (this is Collection && isEmpty()) return false @@ -1655,6 +1661,8 @@ public fun Iterable.minWith(comparator: Comparator): T? { /** * Returns `true` if the collection has no elements. + * + * @sample samples.collections.Collections.Aggregates.none */ public fun Iterable.none(): Boolean { if (this is Collection) return isEmpty() @@ -1663,6 +1671,8 @@ public fun Iterable.none(): Boolean { /** * Returns `true` if no elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate */ public inline fun Iterable.none(predicate: (T) -> Boolean): Boolean { if (this is Collection && isEmpty()) return true diff --git a/js/js.libraries/src/core/generated/_MapsJs.kt b/js/js.libraries/src/core/generated/_MapsJs.kt index 29690bd3bd6..491b526aab8 100644 --- a/js/js.libraries/src/core/generated/_MapsJs.kt +++ b/js/js.libraries/src/core/generated/_MapsJs.kt @@ -86,6 +86,8 @@ public inline fun > Map.mapTo(des /** * Returns `true` if all entries match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public inline fun Map.all(predicate: (Map.Entry) -> Boolean): Boolean { if (isEmpty()) return true @@ -95,6 +97,8 @@ public inline fun Map.all(predicate: (Map.Entry) -> Boole /** * Returns `true` if map has at least one entry. + * + * @sample samples.collections.Collections.Aggregates.any */ public fun Map.any(): Boolean { return !isEmpty() @@ -102,6 +106,8 @@ public fun Map.any(): Boolean { /** * Returns `true` if at least one entry matches the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.anyWithPredicate */ public inline fun Map.any(predicate: (Map.Entry) -> Boolean): Boolean { if (isEmpty()) return false @@ -167,6 +173,8 @@ public fun Map.minWith(comparator: Comparator Map.none(): Boolean { return isEmpty() @@ -174,6 +182,8 @@ public fun Map.none(): Boolean { /** * Returns `true` if no entries match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate */ public inline fun Map.none(predicate: (Map.Entry) -> Boolean): Boolean { if (isEmpty()) return true diff --git a/js/js.libraries/src/core/generated/_SequencesJs.kt b/js/js.libraries/src/core/generated/_SequencesJs.kt index 34a1b0a7d97..92bfdd5368b 100644 --- a/js/js.libraries/src/core/generated/_SequencesJs.kt +++ b/js/js.libraries/src/core/generated/_SequencesJs.kt @@ -922,6 +922,8 @@ public fun Sequence.toMutableSet(): MutableSet { /** * 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 Sequence.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 Sequence.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 Sequence.minWith(comparator: Comparator): 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 Sequence.none(): Boolean { /** * Returns `true` if no elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate * * The operation is _terminal_. */ diff --git a/js/js.libraries/src/core/generated/_StringsJs.kt b/js/js.libraries/src/core/generated/_StringsJs.kt index 576ee758f58..07f614d2ff6 100644 --- a/js/js.libraries/src/core/generated/_StringsJs.kt +++ b/js/js.libraries/src/core/generated/_StringsJs.kt @@ -805,6 +805,8 @@ public fun CharSequence.withIndex(): Iterable> { /** * 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): 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 diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index 029f5cf838e..9d373d6adc2 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -5611,136 +5611,190 @@ public expect infix fun CharArray.union(other: Iterable): Set /** * Returns `true` if all elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public expect inline fun Array.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 Array.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 Array.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): Char? /** * Returns `true` if the array has no elements. + * + * @sample samples.collections.Collections.Aggregates.none */ public expect fun Array.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 Array.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 diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index a9ce9316346..488ea26ef23 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -706,16 +706,22 @@ public expect infix fun Iterable.union(other: Iterable): Set /** * Returns `true` if all elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public expect inline fun Iterable.all(predicate: (T) -> Boolean): Boolean /** * Returns `true` if collection has at least one element. + * + * @sample samples.collections.Collections.Aggregates.any */ public expect fun Iterable.any(): Boolean /** * Returns `true` if at least one element matches the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.anyWithPredicate */ public expect inline fun Iterable.any(predicate: (T) -> Boolean): Boolean @@ -838,11 +844,15 @@ public expect fun Iterable.minWith(comparator: Comparator): T? /** * Returns `true` if the collection has no elements. + * + * @sample samples.collections.Collections.Aggregates.none */ public expect fun Iterable.none(): Boolean /** * Returns `true` if no elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate */ public expect inline fun Iterable.none(predicate: (T) -> Boolean): Boolean diff --git a/libraries/stdlib/common/src/generated/_Maps.kt b/libraries/stdlib/common/src/generated/_Maps.kt index abbd4592c4f..4142f02a634 100644 --- a/libraries/stdlib/common/src/generated/_Maps.kt +++ b/libraries/stdlib/common/src/generated/_Maps.kt @@ -51,16 +51,22 @@ public expect inline fun > Map.ma /** * Returns `true` if all entries match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public expect inline fun Map.all(predicate: (Map.Entry) -> Boolean): Boolean /** * Returns `true` if map has at least one entry. + * + * @sample samples.collections.Collections.Aggregates.any */ public expect fun Map.any(): Boolean /** * Returns `true` if at least one entry matches the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.anyWithPredicate */ public expect inline fun Map.any(predicate: (Map.Entry) -> Boolean): Boolean @@ -105,11 +111,15 @@ public expect fun Map.minWith(comparator: Comparator Map.none(): Boolean /** * Returns `true` if no entries match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate */ public expect inline fun Map.none(predicate: (Map.Entry) -> Boolean): Boolean diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index d2c15dd0d81..c3c0cffd644 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -596,6 +596,8 @@ public expect fun Sequence.toMutableSet(): MutableSet /** * 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 Sequence.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 Sequence.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 Sequence.minWith(comparator: Comparator): 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 Sequence.none(): Boolean /** * Returns `true` if no elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate * * The operation is _terminal_. */ diff --git a/libraries/stdlib/common/src/generated/_Strings.kt b/libraries/stdlib/common/src/generated/_Strings.kt index f70384d9258..2fc15ca3f7c 100644 --- a/libraries/stdlib/common/src/generated/_Strings.kt +++ b/libraries/stdlib/common/src/generated/_Strings.kt @@ -494,16 +494,22 @@ public expect fun CharSequence.withIndex(): Iterable> /** * 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): 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 diff --git a/libraries/stdlib/samples/test/samples/collections/collections.kt b/libraries/stdlib/samples/test/samples/collections/collections.kt index e612a146322..cfffedb06b7 100644 --- a/libraries/stdlib/samples/test/samples/collections/collections.kt +++ b/libraries/stdlib/samples/test/samples/collections/collections.kt @@ -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().all { false }) + } + + @Sample + fun none() { + assertTrue(emptyList().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().none { true }) + } + + @Sample + fun any() { + assertFalse(emptyList().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().any { true }) + } + } + } \ No newline at end of file diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index 3134e3433ed..bc843d872ae 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -9927,6 +9927,8 @@ public infix fun CharArray.union(other: Iterable): Set { /** * Returns `true` if all elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public inline fun Array.all(predicate: (T) -> Boolean): Boolean { for (element in this) if (!predicate(element)) return false @@ -9935,6 +9937,8 @@ public inline fun Array.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 Array.any(): Boolean { return !isEmpty() @@ -10006,6 +10026,8 @@ public fun Array.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 Array.any(predicate: (T) -> Boolean): Boolean { for (element in this) if (predicate(element)) return true @@ -10070,6 +10108,8 @@ public inline fun Array.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): Char? { /** * Returns `true` if the array has no elements. + * + * @sample samples.collections.Collections.Aggregates.none */ public fun Array.none(): Boolean { return isEmpty() @@ -11751,6 +11807,8 @@ public fun Array.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 Array.none(predicate: (T) -> Boolean): Boolean { for (element in this) if (predicate(element)) return false @@ -11815,6 +11889,8 @@ public inline fun Array.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 diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 5d3437d11a8..68b93471dda 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -1383,6 +1383,8 @@ public infix fun Iterable.union(other: Iterable): Set { /** * Returns `true` if all elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public inline fun Iterable.all(predicate: (T) -> Boolean): Boolean { if (this is Collection && isEmpty()) return true @@ -1392,6 +1394,8 @@ public inline fun Iterable.all(predicate: (T) -> Boolean): Boolean { /** * Returns `true` if collection has at least one element. + * + * @sample samples.collections.Collections.Aggregates.any */ public fun Iterable.any(): Boolean { if (this is Collection) return !isEmpty() @@ -1400,6 +1404,8 @@ public fun Iterable.any(): Boolean { /** * Returns `true` if at least one element matches the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.anyWithPredicate */ public inline fun Iterable.any(predicate: (T) -> Boolean): Boolean { if (this is Collection && isEmpty()) return false @@ -1679,6 +1685,8 @@ public fun Iterable.minWith(comparator: Comparator): T? { /** * Returns `true` if the collection has no elements. + * + * @sample samples.collections.Collections.Aggregates.none */ public fun Iterable.none(): Boolean { if (this is Collection) return isEmpty() @@ -1687,6 +1695,8 @@ public fun Iterable.none(): Boolean { /** * Returns `true` if no elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate */ public inline fun Iterable.none(predicate: (T) -> Boolean): Boolean { if (this is Collection && isEmpty()) return true diff --git a/libraries/stdlib/src/generated/_Maps.kt b/libraries/stdlib/src/generated/_Maps.kt index d11c03b317a..7db6a38ae75 100644 --- a/libraries/stdlib/src/generated/_Maps.kt +++ b/libraries/stdlib/src/generated/_Maps.kt @@ -86,6 +86,8 @@ public inline fun > Map.mapTo(des /** * Returns `true` if all entries match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.all */ public inline fun Map.all(predicate: (Map.Entry) -> Boolean): Boolean { if (isEmpty()) return true @@ -95,6 +97,8 @@ public inline fun Map.all(predicate: (Map.Entry) -> Boole /** * Returns `true` if map has at least one entry. + * + * @sample samples.collections.Collections.Aggregates.any */ public fun Map.any(): Boolean { return !isEmpty() @@ -102,6 +106,8 @@ public fun Map.any(): Boolean { /** * Returns `true` if at least one entry matches the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.anyWithPredicate */ public inline fun Map.any(predicate: (Map.Entry) -> Boolean): Boolean { if (isEmpty()) return false @@ -167,6 +173,8 @@ public fun Map.minWith(comparator: Comparator Map.none(): Boolean { return isEmpty() @@ -174,6 +182,8 @@ public fun Map.none(): Boolean { /** * Returns `true` if no entries match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate */ public inline fun Map.none(predicate: (Map.Entry) -> Boolean): Boolean { if (isEmpty()) return true diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index a7287a5faa6..a75050fa013 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -963,6 +963,8 @@ public fun Sequence.toMutableSet(): MutableSet { /** * 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 Sequence.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 Sequence.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 Sequence.minWith(comparator: Comparator): 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 Sequence.none(): Boolean { /** * Returns `true` if no elements match the given [predicate]. + * + * @sample samples.collections.Collections.Aggregates.noneWithPredicate * * The operation is _terminal_. */ diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index d560c554c6a..2b191b9c3db 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -812,6 +812,8 @@ public fun CharSequence.withIndex(): Iterable> { /** * 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): 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 diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt index 4c792a67255..b7c9db29200 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt @@ -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()"