I’ve made another package for chaining/piping data transformations together, similar to Chain.jl and Pipe.jl, stealing some of their ideas but with nicer >>-based syntax and REPL integration.
Here is a little example of using it with TidierData.jl:
julia> using Chevrons, DataFrames, TidierData
julia> Chevrons.enable_repl() # magic to enable Chevrons syntax in the REPL
julia> df = DataFrame(name=["John", "Sally", "Roger"], age=[54, 34, 79], children=[0, 2, 4])
3×3 DataFrame
Row │ name age children
│ String Int64 Int64
─────┼─────────────────────────
1 │ John 54 0
2 │ Sally 34 2
3 │ Roger 79 4
julia> df >> @filter(age > 40) >> @select(num_children=children, age)
2×2 DataFrame
Row │ num_children age
│ Int64 Int64
─────┼─────────────────────
1 │ 0 54
2 │ 4 79
What I particularly like about it:
Less repetititve: You don’t need to write @chain or @pipe every time, you can annotate an entire function, script or module with @chevrons to get the >> syntax.
REPL integration so you can use this syntax automatically.
>> is easier to type than |>.
Side-effects with >>>, similar to Chain.jl’s @aside, e.g. for logging intermediate values.
This is a nice package. I really hope Julia can support syntax like this.
However, I feel overwriting the << and >> operators could be problematic. Why not considering other operators? I think julia have a bunch of unused operators.
You have to opt-in to this syntax with the @chevrons syntax, so it won’t break existing code. It’s purely a syntactic change to code annotated with @chevrons and won’t affect functions that that code calls.
Not currently. @fonsp does Pluto have any hooks that let us transform the AST of a cell before it is evaluated? (Would be cool to also have Chevrons.enable_pluto() or something.)