Skip to content

Commit a652f71

Browse files
Clarify predicate function and empty list behavior (#1197)
1 parent b54a583 commit a652f71

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

modules/ROOT/pages/functions/predicate.adoc

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ CREATE
5454
.Considerations
5555
|===
5656
| `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.
57+
| `all()` returns `true` if `list` is empty because there are no elements to falsify the `predicate`.
5758
|===
5859

5960
.+all()+
@@ -86,6 +87,23 @@ image::predicate_function_example.svg[width="300",role="middle"]
8687
8788
|===
8889
90+
.`all()` on an empty `LIST`
91+
[source, cypher]
92+
----
93+
WITH [] as emptyList
94+
RETURN all(i in emptyList WHERE true) as allTrue, all(i in emptyList WHERE false) as allFalse
95+
----
96+
97+
.Result
98+
[role="queryresult",options="header,footer",cols="2*<m"]
99+
|===
100+
| allTrue | allFalse
101+
102+
| TRUE | TRUE
103+
104+
2+d|Rows: 1
105+
|===
106+
89107
======
90108

91109

@@ -106,6 +124,7 @@ image::predicate_function_example.svg[width="300",role="middle"]
106124
.Considerations
107125
|===
108126
| `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.
127+
| `any()` returns `false` if `list` is empty because there are no elements to satisfy the `predicate`.
109128
|===
110129

111130
.+any()+
@@ -135,6 +154,24 @@ The query returns the `Person` nodes with the `nationality` property value `Amer
135154
136155
|===
137156
157+
158+
.`any()` on an empty `LIST`
159+
[source, cypher]
160+
----
161+
WITH [] as emptyList
162+
RETURN any(i IN emptyList WHERE true) as anyTrue, any(i IN emptyList WHERE false) as anyFalse
163+
----
164+
165+
.Result
166+
[role="queryresult",options="header,footer",cols="2*<m"]
167+
|===
168+
| anyTrue | anyFalse
169+
170+
| FALSE | FALSE
171+
172+
2+d|Rows: 1
173+
|===
174+
138175
======
139176

140177

@@ -312,6 +349,7 @@ xref:syntax/operators.adoc#cypher-comparison[`IS NULL` or `IS NOT NULL`] should
312349
.Considerations
313350
|===
314351
| `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.
352+
| `none()` returns `true` if `list` is empty because there are no elements to violate the `predicate`.
315353
|===
316354

317355
.+none()+
@@ -345,6 +383,23 @@ image::predicate_function_example.svg[width="300",role="middle"]
345383
346384
|===
347385
386+
.`none()` on an empty `LIST`
387+
[source, cypher]
388+
----
389+
WITH [] as emptyList
390+
RETURN none(i IN emptyList WHERE true) as noneTrue, none(i IN emptyList WHERE false) as noneFalse
391+
----
392+
393+
.Result
394+
[role="queryresult",options="header,footer",cols="2*<m"]
395+
|===
396+
| noneTrue | noneFalse
397+
398+
| TRUE | TRUE
399+
400+
2+d|Rows: 1
401+
|===
402+
348403
======
349404

350405

@@ -365,6 +420,7 @@ image::predicate_function_example.svg[width="300",role="middle"]
365420
.Considerations
366421
|===
367422
| `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.
423+
| `single()` returns `false` if `list` is empty because there is not exactly one element satisfying the `predicate`.
368424
|===
369425

370426
.+single()+
@@ -394,4 +450,21 @@ In every returned path there is exactly one node which has the `nationality` pro
394450
395451
|===
396452
453+
.`single()` on an empty `LIST`
454+
[source, cypher]
455+
----
456+
WITH [] as emptyList
457+
RETURN single(i IN emptyList WHERE true) as singleTrue, single(i IN emptyList WHERE false) as singleFalse
458+
----
459+
460+
.Result
461+
[role="queryresult",options="header,footer",cols="2*<m"]
462+
|===
463+
| singleTrue | singleFalse
464+
465+
| FALSE | FALSE
466+
467+
2+d|Rows: 1
468+
|===
469+
397470
======

0 commit comments

Comments
 (0)