函数链

http://lua-users.org/wiki/FiltersSourcesAndSinks

A chain is a function that combines the effect of two (or more) other functions, but whose interface is indistinguishable from the interface of one of its components. Thus, a chained filter can be used wherever an atomic filter can be used. However, its effect on data is the combined effect of its component filters. Note that, as a consequence, chains can be chained themselves to create arbitrarily complex operations that can be used just like atomic operations.

DEMO

local function chain2(f1, f2)
return function(chunk)
local ret = f2(f1(chunk))
if chunk then return ret
else return ret .. f2() end
end
end local filter = {}
function filter.chain(...)
local f = arg[]
for i = , table.getn(arg) do
f = chain2(f, arg[i])
end
return f
end local function addOne( subject )
return subject +
end local function minOne( subject )
return subject -
end local nullFunc = filter.chain(addOne, minOne) local result = nullFunc()
print(result) local nullFunc_1 = filter.chain(minOne, addOne)
local result = nullFunc_1()
print(result)

扩展

Filters can be seen as internal nodes in a network through which data flows, potentially being transformed along its way. Chains connect these nodes together. To complete the picture, we need sources and sinks as initial and final nodes of the network, respectively. Less abstractly, a source is a function that produces new data every time it is called. On the other hand, sinks are functions that give a final destination to the data they receive. Naturally, sources and sinks can be chained with filters.

Finally, filters, chains, sources, and sinks are all passive entities: they need to be repeatedly called in order for something to happen. Pumps provide the driving force that pushes data through the network, from a source to a sink.

http://lua-users.org/wiki/FiltersSourcesAndSinks

Lua 函数链功能的更多相关文章

  1. 使用NGINX+LUA实现WAF功能 和nginx 防盗链

    使用NGINX+LUA实现WAF功能 一.了解WAF 1.1 什么是WAF Web应用防护系统(也称:网站应用级入侵防御系统 .英文:Web Application Firewall,简称: WAF) ...

  2. Lua函数之二

    Lua函数之二 Lua中函数的两个重要特性: 1.函数和其他类型(如number.string)一样,可以存放在变量中,也可以存放在table中,可以作为函数的参数,还可以作为函数的返回值. 2.嵌套 ...

  3. 一些LUA函数(转载)

    转自http://hi.baidu.com/chevallet/item/9a3a6410c20d929198ce3363 一些LUA函数 1.assert (v [, message]) 功能:相当 ...

  4. JQuery常用函数及功能

    JQuery常用函数及功能小结 来源:http://blog.csdn.net/screensky/article/details/7831000 1.文档加载完成执行函数 $(document).r ...

  5. 在Excel中使用频率最高的函数的功能和使用方法

    在Excel中使用频率最高的函数的功能和使用方法,按字母排序: 1.ABS函数 函数名称:ABS 主要功能:求出相应数字的绝对值. 使用格式:ABS(number) 参数说明:number代表需要求绝 ...

  6. C中调用Lua函数

    我们先来看一个简单的例子: lua_State* L = NULL; // 内部调用lua函数 double f(double x, double y) { double z; lua_getglob ...

  7. matlab中subplot函数的功能

    转载自http://wenku.baidu.com/link?url=UkbSbQd3cxpT7sFrDw7_BO8zJDCUvPKrmsrbITk-7n7fP8g0Vhvq3QTC0DrwwrXfa ...

  8. Lua函数之一

    LUA函数之一 函数声明: function foo(arguments) statements end 1.函数调用 调用函数的时候,如果参数列表为空,必须使用()表明是函数调用,例如: os.da ...

  9. ASP.net UrlRewrite的防盗链功能

    ASP.net中如何实现基于UrlRewrite的防盗链. ASP.net中最快实现UrlRewrite的方法这篇文章中说了如何做UrlRewrite,那只是一个最简单的应用 其实利用UrlRewri ...

随机推荐

  1. iis默认文档

    环境 W10 IIS10 输入网址后,显示一个默认首页,在IIS中,一般指定一个根目录下的文件例如index.html 如果要指定子目录下的文件, 例如让 /home/index.html 这个文件成 ...

  2. js中的arguments用法

    //arguments对象并不是一个数组,但是访问单个参数的方式与访问数组元素的方式相同 function show(){ console.log(arguments); //arguments.pu ...

  3. [CTSC2012]熟悉的文章(后缀自动机+动态规划)

    题目描述 阿米巴是小强的好朋友. 在小强眼中,阿米巴是一个作文成绩很高的文艺青年.为了获取考试作文的真谛,小强向阿米巴求教.阿米巴给小强展示了几篇作文,小强觉得这些文章怎么看怎么觉得熟悉,仿佛是某些范 ...

  4. Ubuntu下redis数据库的安装和配置详细过程

    Redis 安装 当前redis最新稳定版本是4.0.9 当前ubuntu虚拟机中已经安装好了redis,以下步骤可以跳过 最新稳定版本下载链接:http://download.redis.io/re ...

  5. GNOME 3.28 启用桌面图标

    原由 GNOME 3.28合并了移除桌面图标支持 Nautilus从此不在支持桌面图标,直到找到新的解决方案 Issues地址:https://gitlab.gnome.org/GNOME/nauti ...

  6. 百度地图API示例:使用vue添加删除覆盖物

    1.index.html <script type="text/javascript" src="http://api.map.baidu.com/api?v=2. ...

  7. 【洛谷P1024一元三次方程求解】

    题目描述 有形如: ax3 + bx2 + cx1 + dx0 = 0 这样的一个一元三次方程.给出该方程中各项的系数( a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在 -100 ...

  8. (sort)P1068 分数线划定 洛谷

    题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,AA市对 所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试.面试分数线根 据计划录取人数的150\% ...

  9. Java封装、继承整理

    封装 3.1封装概念: 提高代码复用性 隐藏实现细节,对外访问提供公共接口 提高安全型 3.2封装举例 机箱就是隐藏实现细节,提供了公共的访问接口 3.3私有private 一般对成员属性的访问动作: ...

  10. 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失 败,原因是出现以下错误: 80080005

    .Net MVC项目,在下载一个Excel的时候总是报错. 解决办法: 在服务器中,运行dcomcnfg打开组件服务, 依次展开"组件服务"->"计算机" ...