You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In other words, this "reformulates" GROQ as a simpler "canonical form", with the syntactic sugar as a layer of conveniences on top of a rich set of pipeline-oriented function calls.
While the practical benefit of doing this, from a user’s perspective, is probably limited, it has an explanatory benefit.
The text was updated successfully, but these errors were encountered:
We can define the pipe operator as a function composition operator, where:
expr | f(args)
is syntactic sugar for:
f(args, expr)
My initial expectation was that it would be equivalent to f(expr, args), similar to how in Python foo.bar(baz) ends up calling bar(foo, baz). This would also make order() less strange as * | order(name) would become order(*, name). It also seems to be the way Elixir works:
The pipe operator |> passes the result of an expression as the first parameter of another expression.
This is different from Haskell's . operator, but isn't that mostly because Haskell has the convention of "the data comes in the last parameter" (which we're not restricted by)?
As an aside, this opens up the opportunity to explain more of the GROQ syntax as being syntactic sugar for functions.
Yes, the order isn't the most important thing, and we could switch it around. I didn't realize Elixir was different, I just skimmed something mentioning the operator. I always thought it annoying that in Haskell you end up with the function first (map fn vals, not map vals fn), though of course that's the convention because it's super helpful for partial function application and currying.
Tiny nitpick/comment: We should probably use pairs here: object("a" => a)
We can define the pipe operator as a function composition operator, where:
is syntactic sugar for:
This is exactly like the
|>
operator in Elixir, or the.
operator in Haskell. For example, this:could be equivalent to:
This explains why
order
can work as a pipe operator, since:is simply:
Of course, right now
order
takes multiple arguments, which will require supporting "leading varargs", but it's not too bad.Similarly, we can invent new functions for richer data manipulation, such as:
and so on.
As an aside, this opens up the opportunity to explain more of the GROQ syntax as being syntactic sugar for functions. For example,
could be equivalent to something like:
which of course is the same as:
In other words, this "reformulates" GROQ as a simpler "canonical form", with the syntactic sugar as a layer of conveniences on top of a rich set of pipeline-oriented function calls.
While the practical benefit of doing this, from a user’s perspective, is probably limited, it has an explanatory benefit.
The text was updated successfully, but these errors were encountered: