Skip to content

Commit 0d0cc92

Browse files
ilya-gSpace Team
authored and
Space Team
committed
Note about all() result on empty collections KT-54835
1 parent 77e03bb commit 0d0cc92

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

libraries/stdlib/common/src/generated/_Arrays.kt

+36
Original file line numberDiff line numberDiff line change
@@ -12531,6 +12531,10 @@ public infix fun CharArray.union(other: Iterable<Char>): Set<Char> {
1253112531
/**
1253212532
* Returns `true` if all elements match the given [predicate].
1253312533
*
12534+
* Note that if the array contains no elements, the function returns `true`
12535+
* because there are no elements in it that _do not_ match the predicate.
12536+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12537+
*
1253412538
* @sample samples.collections.Collections.Aggregates.all
1253512539
*/
1253612540
public inline fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean {
@@ -12541,6 +12545,10 @@ public inline fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean {
1254112545
/**
1254212546
* Returns `true` if all elements match the given [predicate].
1254312547
*
12548+
* Note that if the array contains no elements, the function returns `true`
12549+
* because there are no elements in it that _do not_ match the predicate.
12550+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12551+
*
1254412552
* @sample samples.collections.Collections.Aggregates.all
1254512553
*/
1254612554
public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
@@ -12551,6 +12559,10 @@ public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
1255112559
/**
1255212560
* Returns `true` if all elements match the given [predicate].
1255312561
*
12562+
* Note that if the array contains no elements, the function returns `true`
12563+
* because there are no elements in it that _do not_ match the predicate.
12564+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12565+
*
1255412566
* @sample samples.collections.Collections.Aggregates.all
1255512567
*/
1255612568
public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
@@ -12561,6 +12573,10 @@ public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
1256112573
/**
1256212574
* Returns `true` if all elements match the given [predicate].
1256312575
*
12576+
* Note that if the array contains no elements, the function returns `true`
12577+
* because there are no elements in it that _do not_ match the predicate.
12578+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12579+
*
1256412580
* @sample samples.collections.Collections.Aggregates.all
1256512581
*/
1256612582
public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
@@ -12571,6 +12587,10 @@ public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
1257112587
/**
1257212588
* Returns `true` if all elements match the given [predicate].
1257312589
*
12590+
* Note that if the array contains no elements, the function returns `true`
12591+
* because there are no elements in it that _do not_ match the predicate.
12592+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12593+
*
1257412594
* @sample samples.collections.Collections.Aggregates.all
1257512595
*/
1257612596
public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
@@ -12581,6 +12601,10 @@ public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
1258112601
/**
1258212602
* Returns `true` if all elements match the given [predicate].
1258312603
*
12604+
* Note that if the array contains no elements, the function returns `true`
12605+
* because there are no elements in it that _do not_ match the predicate.
12606+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12607+
*
1258412608
* @sample samples.collections.Collections.Aggregates.all
1258512609
*/
1258612610
public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
@@ -12591,6 +12615,10 @@ public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
1259112615
/**
1259212616
* Returns `true` if all elements match the given [predicate].
1259312617
*
12618+
* Note that if the array contains no elements, the function returns `true`
12619+
* because there are no elements in it that _do not_ match the predicate.
12620+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12621+
*
1259412622
* @sample samples.collections.Collections.Aggregates.all
1259512623
*/
1259612624
public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
@@ -12601,6 +12629,10 @@ public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
1260112629
/**
1260212630
* Returns `true` if all elements match the given [predicate].
1260312631
*
12632+
* Note that if the array contains no elements, the function returns `true`
12633+
* because there are no elements in it that _do not_ match the predicate.
12634+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12635+
*
1260412636
* @sample samples.collections.Collections.Aggregates.all
1260512637
*/
1260612638
public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
@@ -12611,6 +12643,10 @@ public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
1261112643
/**
1261212644
* Returns `true` if all elements match the given [predicate].
1261312645
*
12646+
* Note that if the array contains no elements, the function returns `true`
12647+
* because there are no elements in it that _do not_ match the predicate.
12648+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
12649+
*
1261412650
* @sample samples.collections.Collections.Aggregates.all
1261512651
*/
1261612652
public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {

libraries/stdlib/common/src/generated/_Collections.kt

+4
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,10 @@ public infix fun <T> Iterable<T>.union(other: Iterable<T>): Set<T> {
17161716
/**
17171717
* Returns `true` if all elements match the given [predicate].
17181718
*
1719+
* Note that if the collection contains no elements, the function returns `true`
1720+
* because there are no elements in it that _do not_ match the predicate.
1721+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
1722+
*
17191723
* @sample samples.collections.Collections.Aggregates.all
17201724
*/
17211725
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {

libraries/stdlib/common/src/generated/_Maps.kt

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ public inline fun <K, V, R, C : MutableCollection<in R>> Map<out K, V>.mapTo(des
157157
/**
158158
* Returns `true` if all entries match the given [predicate].
159159
*
160+
* Note that if the map contains no entries, the function returns `true`
161+
* because there are no entries in it that _do not_ match the predicate.
162+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
163+
*
160164
* @sample samples.collections.Collections.Aggregates.all
161165
*/
162166
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {

libraries/stdlib/common/src/generated/_Sequences.kt

+4
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,10 @@ public fun <T> Sequence<T>.toMutableSet(): MutableSet<T> {
11931193

11941194
/**
11951195
* Returns `true` if all elements match the given [predicate].
1196+
*
1197+
* Note that if the sequence contains no elements, the function returns `true`
1198+
* because there are no elements in it that _do not_ match the predicate.
1199+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
11961200
*
11971201
* The operation is _terminal_.
11981202
*

libraries/stdlib/common/src/generated/_Strings.kt

+4
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,10 @@ public fun CharSequence.withIndex(): Iterable<IndexedValue<Char>> {
10541054
/**
10551055
* Returns `true` if all characters match the given [predicate].
10561056
*
1057+
* Note that if the char sequence contains no characters, the function returns `true`
1058+
* because there are no characters in it that _do not_ match the predicate.
1059+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
1060+
*
10571061
* @sample samples.collections.Collections.Aggregates.all
10581062
*/
10591063
public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {

libraries/stdlib/common/src/generated/_UArrays.kt

+16
Original file line numberDiff line numberDiff line change
@@ -5345,6 +5345,10 @@ public fun UShortArray.withIndex(): Iterable<IndexedValue<UShort>> {
53455345
/**
53465346
* Returns `true` if all elements match the given [predicate].
53475347
*
5348+
* Note that if the array contains no elements, the function returns `true`
5349+
* because there are no elements in it that _do not_ match the predicate.
5350+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
5351+
*
53485352
* @sample samples.collections.Collections.Aggregates.all
53495353
*/
53505354
@SinceKotlin("1.3")
@@ -5358,6 +5362,10 @@ public inline fun UIntArray.all(predicate: (UInt) -> Boolean): Boolean {
53585362
/**
53595363
* Returns `true` if all elements match the given [predicate].
53605364
*
5365+
* Note that if the array contains no elements, the function returns `true`
5366+
* because there are no elements in it that _do not_ match the predicate.
5367+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
5368+
*
53615369
* @sample samples.collections.Collections.Aggregates.all
53625370
*/
53635371
@SinceKotlin("1.3")
@@ -5371,6 +5379,10 @@ public inline fun ULongArray.all(predicate: (ULong) -> Boolean): Boolean {
53715379
/**
53725380
* Returns `true` if all elements match the given [predicate].
53735381
*
5382+
* Note that if the array contains no elements, the function returns `true`
5383+
* because there are no elements in it that _do not_ match the predicate.
5384+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
5385+
*
53745386
* @sample samples.collections.Collections.Aggregates.all
53755387
*/
53765388
@SinceKotlin("1.3")
@@ -5384,6 +5396,10 @@ public inline fun UByteArray.all(predicate: (UByte) -> Boolean): Boolean {
53845396
/**
53855397
* Returns `true` if all elements match the given [predicate].
53865398
*
5399+
* Note that if the array contains no elements, the function returns `true`
5400+
* because there are no elements in it that _do not_ match the predicate.
5401+
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
5402+
*
53875403
* @sample samples.collections.Collections.Aggregates.all
53885404
*/
53895405
@SinceKotlin("1.3")

libraries/tools/kotlin-stdlib-gen/src/templates/Aggregates.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -36,6 +36,10 @@ object Aggregates : TemplateGroupBase() {
3636
doc {
3737
"""
3838
Returns `true` if all ${f.element.pluralize()} match the given [predicate].
39+
40+
Note that if the ${f.collection} contains no ${f.element.pluralize()}, the function returns `true`
41+
because there are no ${f.element.pluralize()} in it that _do not_ match the predicate.
42+
See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
3943
"""
4044
}
4145
sample("samples.collections.Collections.Aggregates.all")

0 commit comments

Comments
 (0)