summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2022-06-16 23:58:20 +0200
committerGitHub <noreply@github.com>2022-06-16 23:58:20 +0200
commit2a92176e4c39b423e5ee47c43794639d312bba63 (patch)
tree90c4602946d8caa2d0e08ab4343ee43caa5a71b6
parentf5deed461297b73fbe363fca19a73751a5e5d7d5 (diff)
parent8b97fa4dcd6f0e1e781f06a5542077125fc4bea1 (diff)
Merge pull request #62118 from dalexeev/empty-array-any-all-docs
Clarify `all` and `any` documentation for empty arrays
-rw-r--r--doc/classes/Array.xml10
1 files changed, 7 insertions, 3 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index 94181db95f..c149cdc0e4 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -131,9 +131,10 @@
The callable's method should take one [Variant] parameter (the current array element) and return a boolean value.
[codeblock]
func _ready():
- print([6, 10, 6].all(greater_than_5)) # Prints True (3 elements evaluate to `true`).
- print([4, 10, 4].all(greater_than_5)) # Prints False (1 elements evaluate to `true`).
- print([4, 4, 4].all(greater_than_5)) # Prints False (0 elements evaluate to `true`).
+ print([6, 10, 6].all(greater_than_5)) # Prints True (3/3 elements evaluate to `true`).
+ print([4, 10, 4].all(greater_than_5)) # Prints False (1/3 elements evaluate to `true`).
+ print([4, 4, 4].all(greater_than_5)) # Prints False (0/3 elements evaluate to `true`).
+ print([].all(greater_than_5)) # Prints True (0/0 elements evaluate to `true`).
print([6, 10, 6].all(func(number): return number &gt; 5)) # Prints True. Same as the first line above, but using lambda function.
@@ -142,6 +143,7 @@
[/codeblock]
See also [method any], [method filter], [method map] and [method reduce].
[b]Note:[/b] Unlike relying on the size of an array returned by [method filter], this method will return as early as possible to improve performance (especially with large arrays).
+ [b]Note:[/b] For an empty array, this method [url=https://en.wikipedia.org/wiki/Vacuous_truth]always[/url] returns [code]true[/code].
</description>
</method>
<method name="any" qualifiers="const">
@@ -155,6 +157,7 @@
print([6, 10, 6].any(greater_than_5)) # Prints True (3 elements evaluate to `true`).
print([4, 10, 4].any(greater_than_5)) # Prints True (1 elements evaluate to `true`).
print([4, 4, 4].any(greater_than_5)) # Prints False (0 elements evaluate to `true`).
+ print([].any(greater_than_5)) # Prints False (0 elements evaluate to `true`).
print([6, 10, 6].any(func(number): return number &gt; 5)) # Prints True. Same as the first line above, but using lambda function.
@@ -163,6 +166,7 @@
[/codeblock]
See also [method all], [method filter], [method map] and [method reduce].
[b]Note:[/b] Unlike relying on the size of an array returned by [method filter], this method will return as early as possible to improve performance (especially with large arrays).
+ [b]Note:[/b] For an empty array, this method always returns [code]false[/code].
</description>
</method>
<method name="append">