In R (thanks to magrittr
/dplyr
) you can now call functions without brackets but you can pipe them along instead.
This means that instead of coding this:
> as.character((sqrt(12)^2)
> as.Date("2014-01-01")
You could also do this:
> 12 %>% sqrt %>% .^2 %>% as.character
> "2014-01-01" %>% as.Date
R uses this extensively to edit dataframes. Beyond dataframes, I feel that this syntax is very readable and powerful for creating functional scripts.
Does the julia language have support for something similar?
Yes, in two senses.
So first of all there is |>
, e.g.
12 |> sqrt |> x->x^2 |> string # 11.999999999999998
using Dates # needed in 0.3, baked in to 0.4
"2014-01-1" |> d->Date(d,"yyyy-mm-dd") |> year |> iseven # true
I wouldn't say its very idiomatic Julia though (or R, which the exception of doing operations on a dataframe with dplyr
). There is a discussion about enhancing this type of thing and making the syntax better. You can do a lot of neat things with Lazy.jl right now though!
For DataFrames in particular, its a WIP, but there is DataFramesMeta.jl combined with Lazy.jl, which lets you do things like dplyr
and LINQ
such as (taken from their README):
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)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With