README.md

%F%

Javascript-style arrow (=>) function expressions in R.

library(fu)
f <- c(a, b, c) %F% {a + b * c}
f
#> function (a, b, c) 
#> {
#>     a + b * c
#> }
f(10, 10, 10)
#> [1] 110

basic usage

Functions with no arguments can be expressed with an empty vector c():

greet_user <- c() %F% cat("hi", Sys.getenv("USER"), "!")

For unary functions the use of c is optional:

f <- d %F% {d * d}

Functions with default arguments can be expressed as a named vector:

f <- c(a, b = 10) %F% {a * a * b}

aliases

%F% has two aliases: %f% and %=>% although the latter is less pleasant to type.



mdequeljoe/fu documentation built on May 9, 2019, 8:18 a.m.