函数链

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. POJ2411 铺地砖 Mondriaan's Dream

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15962   Accepted: 923 ...

  2. 构建MFS分布式文件系统

    ++++++++++++++构建MFS分布式文件系统++++++++++++++PB级别:企业存储空间达到PB级别,即100万GB空间.(1PB=1000TB,1TB=1000GB,1GB=1000M ...

  3. base64加密图片处理

    场景:下载html中内嵌的base64加密图片 举个例子,博客园的插入图片有两种方式,一是引用图片链接,二是直接粘贴2进制图片文件.以第二种方式的图片则是以base64加密的方式内嵌在html页面中. ...

  4. 分考场(无向图着色问题)(dfs回溯)

    问题描述 n个人参加某项特殊考试. 为了公平,要求任何两个认识的人不能分在同一个考场. 求是少需要分几个考场才能满足条件. 输入格式 第一行,一个整数n(1<n<100),表示参加考试的人 ...

  5. Wireshark:couldn't run dumpcap in child process(附带Linux下探索过程)

    之前都是直接使用Kali里面安装好的Wireshark和Win下的,Ubuntu的来个小计 PS:解决方法不重要,我觉得更重要的是这个摸索的过程 解决方法 # 安装wireshark sudo apt ...

  6. CodeFroces-- 511div2 C. Enlarge GCD

    题目链接:C. Enlarge GCD 给你一个序列 删除一些数看可以让他们之间的gcd变大如果可以输出删除数量最小的个数 先求出共同 gcd 然后除去 找出出现最多的质数 然后减去就可以了 #inc ...

  7. Sublime Text3—软件安装、package control插件管理

    一.简介 市面上的编辑器纷繁复杂各有优点,好用的编辑器能让你工作事半功倍,先简单介绍下本文主角Sublime Text编辑器,下面简称Sublime. 1.可用于 Windows.Mac OS X 和 ...

  8. 利用SHAPEIT将vcf文件进行基因型(genotype)定相(phasing):查看两个突变是否来源于同一条链(染色体或父本或母本),two mutations carried by the same read

    首先,下载SHAPEIT. 按照里面的步骤安装完后,将vcf文件进行基因型定相,分四步走. 第一步,将vcf文件转化为plink二进制文件(.bed, .bim, .fam). 这一步需要用到GATK ...

  9. 第二十九节,目标检测算法之R-CNN算法详解

    Girshick, Ross, et al. “Rich feature hierarchies for accurate object detection and semantic segmenta ...

  10. Oracle 常用的十大 DDL 对象

    table:(表) 创建表 create table test3 (tid number,tname varchar2(),hiredate date default sysdate); create ...