// TYPES
// see: https://neo4j.com/docs/developer-manual/current/drivers/types/
///// Number /////
RETURN 1 //Integer
RETURN 1.2 //Float
RETURN 2^3 //=> 8
RETURN 8%5 //=> 3
///// Boolean /////
RETURN true
RETURN [true OR true, // true
true XOR false, // true
true XOR true, // false
NOT true] // false
///// Map /////
RETURN {a:1, b:2}
RETURN keys({a:1,b:2,c:3}); //=> ['a', 'b', 'c']
///// String /////
RETURN "abc"
/// note: probably the '=~' operator uses java.util.regex.Matcher#matches() not find()
RETURN "FooBar" =~ 'oBa' //=> false
RETURN "FooBar" =~ '.*oBa.*' //=> true
/// (String, String) -> Boolean
RETURN ["FooBar" STARTS WITH 'Fo', // True
"FooBar" ENDS WITH 'Bar' , // True
"FooBar" CONTAINS 'oBa' ] // True
/// (String, String) -> String
RETURN 'a'+'b' //=> 'ab'
///// List /////
RETURN [1,2,3]
RETURN [1]+[2] //=> [1,2]
// an useful List generator
RETURN range(0,10) //=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
RETURN range(10,20) //=> [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
RETURN range(0,10,2) //=> [0, 2, 4, 6, 8, 10]
/// see: https://neo4j.com/docs/developer-manual/current/cypher/syntax/lists/#syntax-lists
/// (List, Integer) -> a
RETURN range(10,20)[-1] //=> 20
RETURN range(10,20)[2 .. 5] //=> [12, 13, 14]
RETURN range(10,20)[9 .. -2] //=> [12, 13, 14]
RETURN range(10,20)[0 .. -4] //=> [10, 11, 12, 13, 14, 15, 16]
RETURN [x IN range(0,10) WHERE x % 2 = 0 | x] //=> [0, 2, 4, 6, 8, 10]
RETURN filter(x IN range(0,10) WHERE x % 2 = 0) //=> [0, 2, 4, 6, 8, 10]
RETURN reduce(a = 0, x IN range(1,10) | a+x) //=> 55
/// List predicates
RETURN 1 IN [1,2,3] // true
RETURN 10 IN [1,2,3] // false
RETURN [ all(x IN range(2,10,2) WHERE x % 2 = 0), //=> true
all(x IN range(2,10,2)+[1] WHERE x % 2 = 0)] //=> false
RETURN [ any(x IN range(2,10,2) WHERE x % 2 = 1), //=> false
any(x IN range(2,10,2)+[1] WHERE x % 2 = 1)] //=> true
RETURN [ none(x IN range(2,10,2) WHERE x % 2 = 1), //=> true
none(x IN range(2,10,2)+[1] WHERE x % 2 = 1)] //=> false
RETURN [single(x IN range(2,10,2) WHERE x % 2 = 1), //=> false
single(x IN range(2,10,2)+[1] WHERE x % 2 = 1)] //=> true
// List <=> VALUES(rows)
UNWIND[1,2,3] AS xs
RETURN xs //=> 1,2,3
UNWIND[1,2,3] AS xs
RETURN collect(xs) //=> [1,2,3]
// CASE
WITH 14 AS i
RETURN CASE
WHEN i % 4 = 0 THEN 1
WHEN i % 3 = 0 THEN 2
WHEN i % 2 = 0 THEN 3
ELSE 4
END //=> 3
// RETURN
UNWIND[1,2,3] AS xs
RETURN xs
SKIP 1 //=> 2,3
UNWIND[1,2,3] AS xs
RETURN xs
LIMIT 2 //=> 1,2
UNWIND[3,4,1,68,2,4] AS xs
RETURN xs
ORDER BY xs
UNWIND[3,4,1,68,2,4] AS xs
RETURN xs
ORDER BY xs DESC
UNWIND[1,2,3,3,1,3,4] AS xs
RETURN DISTINCT xs //=> 1,2,3,4
// !! ERROR !!
// UNWIND range(1,5) AS xs
// RETURN xs
// UNION ALL
// UNWIND range(10,15) AS ys
// RETURN ys
// Utils
/// generate a random List index
WITH range(0,10) AS l
WITH length(l) AS size
RETURN toInt(floor(rand() * size));