Provide a way to order lists
CIR-2017-190
When collect(...)ing values, it should be possible to order the collected elements.
It would also be nice to be able to (re-)order an existing collection, for instance through the use of comprehension.
Idea:
MATCH (p:Person)-[:KNOWS]-(friend) RETURN p.name, collect(friend.name ORDER BY friend.age DESC)
Idea for ordering already collected lists:
WITH [1, 0, 5, -3] AS list
WITH [e IN list | e ORDER BY e] AS orderedList
RETURN orderedList
I feel like this fits well with the language in its current form, but it's not very elegant. Perhaps just using DESC and ASC as unary operators could be another alternative:
WITH [1, 0, 5, -3] AS list
WITH list DESC AS orderedList
RETURN orderedList
Using ASC or DESC as unary operators could be added as a syntactic sugar. However, in case of a list of nodes, property access needs to be specified to allow sorting, so I see the verbose form as a must have.