r - 统计编程语言 R 中的默认编程是否可行?

标签 r functional-programming tacit-programming

<分区>

tacit programming也称为无点样式 - R 中的一个选项?

最佳答案

检查 magrittr包,因为它似乎最接近您的要求。 Wikipedia引用一个例子:

For example, a sequence of operations in an applicative language like the following:

def example(x):
   y = foo(x)
   z = bar(y)
   w = baz(z)
   return w

...is written in point-free style as the composition of a sequence of functions, without parameters:

def example: baz bar foo

在带有 magrittr 的 R 中,它可以写成

x %>% foo %>% bar %>% baz

其中 %>% 运算符用于组成函数链,以便将前一个函数的输出作为后续函数的第一个参数传递。请参阅 magrittr 小插图以了解更多信息。

可以定义函数

# explicitly
example <- function(x) x %>% foo %>% bar %>% baz

# or simply (as @bergant noticed)
example <- . %>% foo %>% bar %>% baz

关于r - 统计编程语言 R 中的默认编程是否可行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30121731/

相关文章:

ruby - 在 Ruby 中乱序柯里化(Currying)

j - 是 J 关联的火车

function - Haskell 中的隐性函数组合

sql-server - 将数据从 Microsoft SQL Server 读取到 R 中

r - 如何使用 RMongo 计算特定列的平均值?

r - 在直方图上显示平均值

haskell - 的 是什么意思? Haskell 中的记录语法如何做?

r - dplyr 改变列范围的行列最大值

javascript - 为什么 Monad 的 bind() 方法必须返回一个 func,然后返回一个 Monad?

rust - 在 Rust 中可以进行默认编程吗?