Skip to content

Commit b93e888

Browse files
Clarify iterative functions (#1224)
1 parent a5cfef2 commit b93e888

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

modules/ROOT/pages/functions/list.adoc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,23 @@ Three lists of numbers in the given ranges are returned.
230230

231231
.Details
232232
|===
233-
| *Syntax* 3+| `reduce(accumulator, variable)`
233+
| *Syntax* 3+| `reduce(accumulator = initial, variable IN list \| expression)`
234234
| *Description* 3+| Runs an expression against individual elements of a `LIST<ANY>`, storing the result of the expression in an accumulator.
235-
.3+| *Arguments* | *Name* | *Type* | *Description*
236-
| `accumulator` | `ANY` | A variable that holds the result as the list is iterated.
237-
| `variable` | `LIST<ANY>` | A variable that can be used within the reducing expression.
235+
.6+| *Arguments* | *Name* | *Type* | *Description*
236+
| `accumulator` | `ANY` | A variable that holds the result as the `list` is iterated.
237+
Starts with an `initial` value.
238+
| `initial` | `ANY` | The starting value of the `accumulator`.
239+
| `variable` | `ANY` | A variable that represents each element in the `list` during iteration.
240+
| `list` | `LIST<ANY>` | The `list` that is being iterated over.
241+
| `expression` | `ANY` | An expression that updates the `accumulator` with each iteration.
238242
| *Returns* 3+| `ANY`
239243
|===
240244

241-
This function is analogous to the `fold` or `reduce` method in functional languages such as Lisp and Scala.
242-
245+
.Considerations
246+
|===
247+
|`reduce()` differs from most Cypher functions because it iterates over a list, incrementally updating an accumulator with each element based on an expression, rather than returning a result from a single evaluation.
248+
As such, Cypher's `reduce()` is analogous to the `fold` or `reduce` methods in functional languages such as Lisp and Scala.
249+
|===
243250

244251
.+reduce()+
245252
======

modules/ROOT/pages/functions/predicate.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ CREATE
5353

5454
.Considerations
5555
|===
56+
| `all()` differs from most Cypher functions because it iterates over a list, evaluating an expression for each element, rather than returning a result from a single evaluation.
5657
| `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.
5758
| `all()` returns `true` if `list` is empty because there are no elements to falsify the `predicate`.
5859
|===
@@ -123,6 +124,7 @@ RETURN all(i in emptyList WHERE true) as allTrue, all(i in emptyList WHERE false
123124

124125
.Considerations
125126
|===
127+
| `any()` differs from most Cypher functions because it iterates over a list, evaluating an expression for each element, rather than returning a result from a single evaluation.
126128
| `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.
127129
| `any()` returns `false` if `list` is empty because there are no elements to satisfy the `predicate`.
128130
|===
@@ -348,6 +350,7 @@ xref:syntax/operators.adoc#cypher-comparison[`IS NULL` or `IS NOT NULL`] should
348350

349351
.Considerations
350352
|===
353+
| `none()` differs from most Cypher functions because it iterates over a list, evaluating an expression for each element, rather than returning a result from a single evaluation.
351354
| `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.
352355
| `none()` returns `true` if `list` is empty because there are no elements to violate the `predicate`.
353356
|===
@@ -419,6 +422,7 @@ RETURN none(i IN emptyList WHERE true) as noneTrue, none(i IN emptyList WHERE fa
419422

420423
.Considerations
421424
|===
425+
| `single()` differs from most Cypher functions because it iterates over a list, evaluating an expression for each element, rather than returning a result from a single evaluation.
422426
| `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.
423427
| `single()` returns `false` if `list` is empty because there is not exactly one element satisfying the `predicate`.
424428
|===

0 commit comments

Comments
 (0)