I'm sure some of us who are out of the loop might be wondering: what about the magrittr pipe operator (%>%) that we all know and love?<p>Luke Tierney explains the move from %>% to a native pipe |> here [1]. The native pipe aims to be more efficient as well as addresses issues with the magrittr pipe like complex stack traces.<p>Turns out the |> syntax is also used in Julia, Javascript and F#.<p>The lambda syntax (\(x) -> x + 1) is similar to Haskell's (\x -> x + 1).<p>[1] <a href="https://www.youtube.com/watch?v=X_eDHNVceCU&feature=youtu.be&t=3099" rel="nofollow">https://www.youtube.com/watch?v=X_eDHNVceCU&feature=youtu.be...</a>
The R "userland" pipe magrittr has been altered to make it more compatible with the proposed base pipe, as well:<p><a href="https://www.tidyverse.org/blog/2020/11/magrittr-2-0-is-here/" rel="nofollow">https://www.tidyverse.org/blog/2020/11/magrittr-2-0-is-here/</a>
These will both come in pretty handy, although the first is just a formalization of something that's already available in packages, the lambda syntax will clean up code a fair bit, and make realtime analysis easier to type.
Question by someone who is ignorant but interested in functional programming: what is the closest equivalent to these functions in Python? (Or correct me if I'm asking the wrong question).<p>I used to love using lambdas in Python, along with map/reduce/filter but for whatever reason the Python community has turned against it. Map and filter can now be nicely done with list comprehensions, although I still haven't found a decent one-line equivalent for reduce (other then importing functools).
I wish more languages gave us a "|>" operator. Too many languages settle with dot notation, which confuses encapsulation/method calling with syntactical convenience.
Kind of odd they didn't decide to go with the magrittr syntax, which is in common use and heavily promoted in dplyr / tidyverse.<p>I wonder if RStudio will change its `ctrl` + `shift` + m shortcut from the magrittr ( %>% ) style pipes to these new pipes ( |> )
This sounds promising, but how do we type that pipe easily if we're going to be using it all the time? I actually like %>% because it's easy to reach the keys and hammer it out. Agreed on the ugly stack traces.
For people asking how one could possibly ever manage to chain operations in python without a pipe operator: <a href="https://github.com/tpapastylianou/chain-ops-python" rel="nofollow">https://github.com/tpapastylianou/chain-ops-python</a><p>Same principle in octave: <a href="https://github.com/tpapastylianou/chain-ops-octave" rel="nofollow">https://github.com/tpapastylianou/chain-ops-octave</a>
The lambda thing may be useful. Sometimes I was tempted to do something like this<p><pre><code> > f <- function(expr) eval(substitute( function(x) expr ))
> sapply(1:4, f({ a <- x^2 ; b <- x^3 ; a+b }))
[1] 2 12 36 80
</code></pre>
but I'm not sure it would have worked well. The new syntax is of course also more flexible.
Well, afaik it isn't really a pipe but syntactic sugar. A pipe streams data from one output stream to an input stream. This rewrites the code as if the input were passed as an argument.
personally Im surprised R is still in active development when the main use case for people to use R (at least when I was using it) was for statistical analysis. Python with its libraries (a lot I believe ported from R) just does is nicer, and faster.