Open mikmart opened 2 years ago
What would be nice here is a compose operator.
Consider this example. We need to use list
here because otherwise by
strips the class.
x <- .Date(1:3)
g <- c("a", "a", "b")
do.call("c", by(x, g, function(z) list(min(z))))
The function part can be expressed as shown below using magrittr:
library(magrittr)
do.call("c", by(x, g, . %>% min %>% list))
but it would be expressible in a more compact form if there were a compose operator. Suppose we call it $.>%
and that f %.>% g
is regarded to be equivalent to . %>% f %>% g
. Then we could reduce the above to:
do.call("c", by(x, g, min %.>% list))
Inspired by this StackOverflow question, I was wondering if it might be useful to have a function to create functional sequences? AFAIK, the only way to create a
fseq
is to start a pipe sequence with.
:For defining each step in the sequence programmatically, it might be nice to have other interfaces. Perhaps something like this to create the above?
I haven’t thought about how to actually implement these, but I was wondering if this might be something that could potentially be added to magrittr?