R语言函数式编程概念
- functional 泛函
R语言的函数是first-class function 一等函数,higher-order function高阶函数,函数可以作为函数参数传入,这些特性可以设计map/reduce/accumulate/filter 等操作
有关first-class,大牛的定义:
The rights and privileges of first-class citizens:
- To be named by variables.
- To be passed as arguments to procedures.
- To be returned as values of procedures.
- To be incorporated into data structures
-
function factory 函数工厂
利用函数的闭包性质,把函数的environment中的一些参数固定下来,形成新的函数。
在别的语言的编程范式中是工厂模式? -
function operator 函数操作子
利用函数的闭包性质,在函数的前或后增加一下前置操作或后置操作,形成新的函数。
在别的语言的编程范式中常常称之为Decorator模式。
参考AdvancedR的Functional Programming章节