Make @chain base Julia

Lincoln_Hannah
Fri, 12 Nov 2021 00:52:23 +0000
General Usage

Instead of having the @chain macro, how about making the previous line’s output always available (if you want it) through “_” or by omitting the first argument of a function.
So you could write something like.

1:5
sum

julia> 15

or

1:5
DataFrame(A=_)
@rtransform :B = :A + 1
@with :B
sum

julia> 20

If you need to break a given chain you could just store the current value to a global variable X=_ then use it to resume at any point.
→ X might also be a nice shorthand for X= _

A single . on a line could mean the following line or block operates on an element-wise level like .|> so variables defined within the block would not have global scope.
The above example could be written

1:5
.
begin
    A = _
    B = A + 1
end
sum

This could remove the need for both the @chain and @pipe macros
Rather than something |> something |> something
you would write something ; something ; something

I find 90% of my code is within @chain blocks. It would save a lot of code to have the functionality by default.

4 posts - 4 participants