Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete @> reference, add chain #220

Merged
merged 3 commits into from
Jan 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,38 +414,34 @@ more obvious with less noise from `@` symbols. This approach also
avoids filling up the limited macro name space. The main downside is
that more magic happens under the hood.

Alternatively you can use Lazy.jl `@>` macro like this:
Alternatively you can use Chain.jl, which exports the `@chain` macro. With Chain.jl,
there is no need for `|>` and the first result of the previous expression is
pdeffebach marked this conversation as resolved.
Show resolved Hide resolved
assumed to be the first argument of the current call, unless otherwise specified
with `_`.

```julia
using Lazy: @>
using Chain, Statistics

df = DataFrame(a = repeat(1:5, outer = 20),
b = repeat(["a", "b", "c", "d"], inner = 25),
x = repeat(1:20, inner = 5))

x_thread = @> begin
df
@transform(y = 10 * :x)
@where(:a .> 2)
@by(:b, meanX = mean(:x), meanY = mean(:y))
@orderby(:meanX)
@select(:meanX, :meanY, var = :b)
x_thread = @chain df begin
@transform(_, y = 10 * :x)
@where(_, :a .> 2)
@by(_, :b, meanX = mean(:x), meanY = mean(:y))
@orderby(_, :meanX)
@select(_, :meanX, :meanY, var = :b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought _ as the first argument was implicit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, sorry about that. fixed.

end
```

!!! note
Please note that Lazy exports the function `groupby` which would clash
with `DataFrames.groupby`. Hence, it is recommended that you only import a
select number of functions into the namespace by only importing `@>` e.g.
`using Lazy: @>` instead of `using Lazy`.

Another alternative is Pipe.jl which exports the `@pipe` macro for piping.
The piping mechanism in Pipe requires explicit specification of the piped
object via `_` instead of assuming it is the first argument to the next function.
The Pipe.jl equivalent of the above is:

```julia
using Pipe
using Pipe, Statistics

df = DataFrame(a = repeat(1:5, outer = 20),
b = repeat(["a", "b", "c", "d"], inner = 25),
Expand Down