Chain.jl
Chain.jl copied to clipboard
Chain as pipe argument
Parentheses are necessary to put a chain in a pipe. For example the following
@chain DataFrame(a=1:3) begin select(:a) end |> display
fails with
ERROR: MethodError: no method matching select(::Symbol)
Closest candidates are:
select(::AbstractDataFrame, ::Any...; copycols, renamecols) at ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:940
select(::Union{Function, Type}, ::AbstractDataFrame; renamecols) at ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/selection.jl:943
select(::Union{Function, Type}, ::GroupedDataFrame; copycols, keepkeys, ungroup, renamecols) at ~/.julia/packages/DataFrames/vuMM8/src/groupeddataframe/splitapplycombine.jl:711
Would it be possible to make this work without parentheses? Intuitively it seems that it should be possible since the chained code is already delimited by the begin ... end block.
This seems a bit problematic because of the other @chain mode where you can do @chain x y z, then I'd have to separate normal |> calls from those after begin end and this sounds edge-casey to me..
In your example you can of course put display after select
Agreed, though I still think it would be nice if @chain blocks were composable with other pipeline code (mainly because for me a @chain block is often a logical unit, like in the example where putting display inside would work but is less clear I think than a processing block followed by some "unrelated" action).