Note about all() result on empty collections KT-54835

This commit is contained in:
Ilya Gorbunov
2022-11-24 21:48:57 +01:00
committed by Space Team
parent 77e03bb769
commit 0d0cc9250b
7 changed files with 73 additions and 1 deletions
@@ -12531,6 +12531,10 @@ public infix fun CharArray.union(other: Iterable<Char>): Set<Char> {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
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 {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
@@ -12551,6 +12559,10 @@ public inline fun ByteArray.all(predicate: (Byte) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
@@ -12561,6 +12573,10 @@ public inline fun ShortArray.all(predicate: (Short) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
@@ -12571,6 +12587,10 @@ public inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
@@ -12581,6 +12601,10 @@ public inline fun LongArray.all(predicate: (Long) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
@@ -12591,6 +12615,10 @@ public inline fun FloatArray.all(predicate: (Float) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
@@ -12601,6 +12629,10 @@ public inline fun DoubleArray.all(predicate: (Double) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
@@ -12611,6 +12643,10 @@ public inline fun BooleanArray.all(predicate: (Boolean) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun CharArray.all(predicate: (Char) -> Boolean): Boolean {
@@ -1716,6 +1716,10 @@ public infix fun <T> Iterable<T>.union(other: Iterable<T>): Set<T> {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the collection contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
@@ -157,6 +157,10 @@ 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].
*
* Note that if the map contains no entries, the function returns `true`
* because there are no entries in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean {
@@ -1193,6 +1193,10 @@ public fun <T> Sequence<T>.toMutableSet(): MutableSet<T> {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the sequence contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* The operation is _terminal_.
*
@@ -1054,6 +1054,10 @@ public fun CharSequence.withIndex(): Iterable<IndexedValue<Char>> {
/**
* Returns `true` if all characters match the given [predicate].
*
* Note that if the char sequence contains no characters, the function returns `true`
* because there are no characters in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
public inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean {
@@ -5345,6 +5345,10 @@ public fun UShortArray.withIndex(): Iterable<IndexedValue<UShort>> {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
@SinceKotlin("1.3")
@@ -5358,6 +5362,10 @@ public inline fun UIntArray.all(predicate: (UInt) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
@SinceKotlin("1.3")
@@ -5371,6 +5379,10 @@ public inline fun ULongArray.all(predicate: (ULong) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
@SinceKotlin("1.3")
@@ -5384,6 +5396,10 @@ public inline fun UByteArray.all(predicate: (UByte) -> Boolean): Boolean {
/**
* Returns `true` if all elements match the given [predicate].
*
* Note that if the array contains no elements, the function returns `true`
* because there are no elements in it that _do not_ match the predicate.
* See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
*
* @sample samples.collections.Collections.Aggregates.all
*/
@SinceKotlin("1.3")
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -36,6 +36,10 @@ object Aggregates : TemplateGroupBase() {
doc {
"""
Returns `true` if all ${f.element.pluralize()} match the given [predicate].
Note that if the ${f.collection} contains no ${f.element.pluralize()}, the function returns `true`
because there are no ${f.element.pluralize()} in it that _do not_ match the predicate.
See a more detailed explanation of this logic concept in ["Vacuous truth"](https://en.wikipedia.org/wiki/Vacuous_truth) article.
"""
}
sample("samples.collections.Collections.Aggregates.all")