The pipe operator

Reading multiple nested functions can be taxing on the brain. The previous example, collect(keys(attrs(dom.root))), can be rewritten to improve readability using Julia's pipe operator, |>.

For example, the following snippet nests three function calls, each inner function becoming the argument of the outermost one:

julia> collect(keys(attrs(dom.root))) 
3-element Array{AbstractString,1}: 
 "class" 
 "lang" 
 "dir"

This can be rewritten for improved readability as a chain of functions using the pipe operator. This code produces the exact same result:

julia> dom.root |> attrs |> keys |> collect 
3-element Array{AbstractString,1}: 
 "class" 
 "lang" 
 "dir" 

What the |> operator does is that it takes the output of the first value and pipes ...

Get Julia Programming Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.