Q:

Combine array with Cypher (Neo4j)

When I have a string that looks something like this:
"app-server/src/test/java/de/something/"
How would I get any possible combination like:
app-server/, app-server/src, app-server/src/test, ....
I can obviously split it with '/' and then I have an array of the parts.  I can also manually append all of these and then filter the null
...
WITH split(package.path,'/')[..size(split(package.path,'/'))-1]
WITH pathParts,
pathParts[0] AS p01,
pathParts[0] + '/' + pathParts[1] AS p02,
pathParts[0] + '/' + pathParts[1] + '/' + pathParts[2] AS p03,
...

An alternative:
WITH pathParts[0] AS p01,
reduce(s = pathParts[0], x IN pathParts[1..2] | s + '/' + x) + '/' AS p02,
reduce(s = pathParts[0], x IN pathParts[1..3] | s + '/' + x) + '/' AS p03,
reduce(s = pathParts[0], x IN pathParts[1..4] | s + '/' + x) + '/' AS p04,
...

But those are both horrible solution. 

I would also want to create Parent-Child relationships from all of these:
(childPackage:Package)-[:HAS_PARENT]->(parentPackage:Package)
e.g. (app-server/src)-[:HAS_PARENT]->(app-server/)

A:

It is necessary to split the string, remove the empty elements from the array, and walk through each element while join all the previous ones:
WITH "app-server/src/test/java/de/something/" AS path
WITH FILTER(p in SPLIT(path, "/") WHERE SIZE(p) > 0) AS pathParts
UNWIND RANGE(0, SIZE(pathParts)-1) AS i
RETURN REDUCE(acc = "", p IN pathParts[0..i+1] | acc + p + '/') AS pathPart

And it will not be a problem to go through the second time in order to link them:
WITH "app-server/src/test/java/de/something/" AS path
WITH FILTER(p in SPLIT(path, "/") WHERE SIZE(p) > 0) AS pathParts
UNWIND RANGE(0, SIZE(pathParts)-1) AS i
WITH collect(REDUCE(acc = "", p IN pathParts[0..i+1] | acc + p + '/')) AS pathParts

UNWIND RANGE(1, SIZE(pathParts)-1) AS i
  MERGE (P1:Package {path: pathParts[i-1]})
  MERGE (P2:Package {path: pathParts[i]})
  MERGE (P2)-[r:hasParent]->(P1)
RETURN P1, r, P2

