(filter (> age 20))
That second form to filter should be a function, but in this case it is an expression that returns a boolean and is not itself a function.
(filter (> age 20))
That second form to filter should be a function, but in this case it is an expression that returns a boolean and is not itself a function.
(->> ($alice) (assoc $friends) (assoc $friends) (filter (> age 20)) (count))
...in Gremlin is: g.V(alice).out("friends").out("friends").has("age",gt(20)).count()I'm pretty sure this is Clojure or something very close to it. ->> is the thread-last macro. What it does is take the first expression, ($alice) and inserts it as the last expr in the next form so that the second step (assoc $friends) would eval to (assoc $friends $alice). It continues this by inserting this expr into the last part of the next form. So the example would reduce to: (filter (> age 20) (assoc $friends (assoc $friends $alice)))
i.e. while walking, we notice a function (> age 20) and age isn't visible in scope. We thus rewrite that into something like (fn [age] (> age 20)) or (fn [x] (> (:age x) 20)).
I've taken this approach before with DSLs. It makes for extremely fast to write business logic where business users don't have to care as much about where their data comes from (they just need field names).