The ASSIGN keyword is what variable and function assignments in pipe operator syntax are implicitly translated to. The below expression:
hn <| https://news.ycombinator.com |
Is equivalent to the following expression:
ASSIGN hn https://news.ycombinator.com
Another way to view the ASSIGN keyword is like the alias command in shell.
In order to get the post titles and links from the front page of hacker news, we’ll need the following values in addition to the exact URL of the page we’re interested in:
href
attribute of the link associated with the postIn our favor, the last two values belong to the same anchor tag allowing us to succinctly assign the href attribute in the below block of assignments:
-- The URL we're interested in
hn <| https://news.ycombinator.com |
-- The repeating container that wraps each post
container <| span.titleline |
-- The element containing the title of a post
post <| a |
-- The element's href attribute for its link
post_link <| a@href |
The benefit of this is you then get a resulting query statement at the end that’s more readable than what you’d otherwise construct in a different framework.
FROM hn
|> GROUP BY container
|> SELECT post, post_link
Putting it all together gives us:
-- The URL we're interested in
hn <| https://news.ycombinator.com |
-- The repeating container that wraps each post
container <| span.titleline |
-- The element containing the title of a post
post <| a |
-- The element's href attribute for its link
post_link <| a@href |
FROM hn
|> GROUP BY container
|> SELECT post, post_link