Skip to content

Commit

Permalink
Clarify predicate function and empty list behavior (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
JPryce-Aklundh committed Feb 26, 2025
1 parent b54a583 commit a652f71
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions modules/ROOT/pages/functions/predicate.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ CREATE
.Considerations
|===
| `null` is returned if the `list` is `null` or if the `predicate` evaluates to `null` for at least one element and does not evaluate to false for any other element.
| `all()` returns `true` if `list` is empty because there are no elements to falsify the `predicate`.
|===

.+all()+
Expand Down Expand Up @@ -86,6 +87,23 @@ image::predicate_function_example.svg[width="300",role="middle"]
|===
.`all()` on an empty `LIST`
[source, cypher]
----
WITH [] as emptyList
RETURN all(i in emptyList WHERE true) as allTrue, all(i in emptyList WHERE false) as allFalse
----
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| allTrue | allFalse
| TRUE | TRUE
2+d|Rows: 1
|===
======


Expand All @@ -106,6 +124,7 @@ image::predicate_function_example.svg[width="300",role="middle"]
.Considerations
|===
| `null` is returned if the `list` is `null` or if the `predicate` evaluates to `null` for at least one element and does not evaluate to false for any other element.
| `any()` returns `false` if `list` is empty because there are no elements to satisfy the `predicate`.
|===

.+any()+
Expand Down Expand Up @@ -135,6 +154,24 @@ The query returns the `Person` nodes with the `nationality` property value `Amer
|===
.`any()` on an empty `LIST`
[source, cypher]
----
WITH [] as emptyList
RETURN any(i IN emptyList WHERE true) as anyTrue, any(i IN emptyList WHERE false) as anyFalse
----
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| anyTrue | anyFalse
| FALSE | FALSE
2+d|Rows: 1
|===
======


Expand Down Expand Up @@ -312,6 +349,7 @@ xref:syntax/operators.adoc#cypher-comparison[`IS NULL` or `IS NOT NULL`] should
.Considerations
|===
| `null` is returned if the `list` is `null`, or if the `predicate` evaluates to `null` for at least one element and does not evaluate to `true` for any other element.
| `none()` returns `true` if `list` is empty because there are no elements to violate the `predicate`.
|===

.+none()+
Expand Down Expand Up @@ -345,6 +383,23 @@ image::predicate_function_example.svg[width="300",role="middle"]
|===
.`none()` on an empty `LIST`
[source, cypher]
----
WITH [] as emptyList
RETURN none(i IN emptyList WHERE true) as noneTrue, none(i IN emptyList WHERE false) as noneFalse
----
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| noneTrue | noneFalse
| TRUE | TRUE
2+d|Rows: 1
|===
======


Expand All @@ -365,6 +420,7 @@ image::predicate_function_example.svg[width="300",role="middle"]
.Considerations
|===
| `null` is returned if the `list` is `null`, or if the `predicate` evaluates to `null` for at least one element and does not evaluate to `true` for any other element.
| `single()` returns `false` if `list` is empty because there is not exactly one element satisfying the `predicate`.
|===

.+single()+
Expand Down Expand Up @@ -394,4 +450,21 @@ In every returned path there is exactly one node which has the `nationality` pro
|===
.`single()` on an empty `LIST`
[source, cypher]
----
WITH [] as emptyList
RETURN single(i IN emptyList WHERE true) as singleTrue, single(i IN emptyList WHERE false) as singleFalse
----
.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| singleTrue | singleFalse
| FALSE | FALSE
2+d|Rows: 1
|===
======

0 comments on commit a652f71

Please sign in to comment.