Lua 函数链功能
函数链
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 函数链功能的更多相关文章
- 使用NGINX+LUA实现WAF功能 和nginx 防盗链
使用NGINX+LUA实现WAF功能 一.了解WAF 1.1 什么是WAF Web应用防护系统(也称:网站应用级入侵防御系统 .英文:Web Application Firewall,简称: WAF) ...
- Lua函数之二
Lua函数之二 Lua中函数的两个重要特性: 1.函数和其他类型(如number.string)一样,可以存放在变量中,也可以存放在table中,可以作为函数的参数,还可以作为函数的返回值. 2.嵌套 ...
- 一些LUA函数(转载)
转自http://hi.baidu.com/chevallet/item/9a3a6410c20d929198ce3363 一些LUA函数 1.assert (v [, message]) 功能:相当 ...
- JQuery常用函数及功能
JQuery常用函数及功能小结 来源:http://blog.csdn.net/screensky/article/details/7831000 1.文档加载完成执行函数 $(document).r ...
- 在Excel中使用频率最高的函数的功能和使用方法
在Excel中使用频率最高的函数的功能和使用方法,按字母排序: 1.ABS函数 函数名称:ABS 主要功能:求出相应数字的绝对值. 使用格式:ABS(number) 参数说明:number代表需要求绝 ...
- C中调用Lua函数
我们先来看一个简单的例子: lua_State* L = NULL; // 内部调用lua函数 double f(double x, double y) { double z; lua_getglob ...
- matlab中subplot函数的功能
转载自http://wenku.baidu.com/link?url=UkbSbQd3cxpT7sFrDw7_BO8zJDCUvPKrmsrbITk-7n7fP8g0Vhvq3QTC0DrwwrXfa ...
- Lua函数之一
LUA函数之一 函数声明: function foo(arguments) statements end 1.函数调用 调用函数的时候,如果参数列表为空,必须使用()表明是函数调用,例如: os.da ...
- ASP.net UrlRewrite的防盗链功能
ASP.net中如何实现基于UrlRewrite的防盗链. ASP.net中最快实现UrlRewrite的方法这篇文章中说了如何做UrlRewrite,那只是一个最简单的应用 其实利用UrlRewri ...
随机推荐
- Diagnostic Trouble Code诊断故障码
所有电子控制单元(ECU)都会根据整车厂规范要求对相关故障进行记录,并储存在NVM(也称作EEPROM)相当于平常电脑上硬盘里.除故障代码外,还会记录故障发生时相关整车情况(如供电电压,环境温度 ...
- 20165223 week2测试补交与总结
测试题二 题目: 在Ubuntu或Windows命令行中 建如下目录结构 Hello.java的内容见附件package isxxxx; (xxxx替换为你的四位学号) 编译运行Hello.java ...
- 华东交通大学2018年ACM“双基”程序设计竞赛部分题解
链接:https://ac.nowcoder.com/acm/contest/221/C来源:牛客网 C-公式题(2) 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其 ...
- 简明的Python教程当中的几个疑惑点分析#1
#1简明的Python教程中的第11章面向对象编程学习中的类与对象的方法里面 有这么一个案例:使用类与对象的变量 #coding:utf-8 #类与对象的变量学习 class Person: popu ...
- DHU--1247 Hat’s Words && HiHocder--1014 Trie树 (字典树模版题)
题目链接 DHU--1247 Hat’s Words HiHocder--1014 Trie树 两个一个递归方式一个非递归 HiHocoder #include<bits/stdc++.h> ...
- staitc
一.static和非static变量 1. static 修饰的变量称为类变量或全局变量或成员变量,在类被加载的时候成员变量即被初始化,与类关联,只要类存在,static变量就存在.非static修饰 ...
- Spring 依赖注入优化
Spring 依赖注入优化 原创: carl.zhao SpringForAll社区 今天 Spring 最大的好处就是依赖注入,关于什么是依赖注入,在Stack Overflow上面有一个问题,如何 ...
- C#两个实体之间相同属性的映射
public static R Mapping<R, T>(T model) { R result = Activator.CreateInstance<R>(); forea ...
- 物联网温度服务器-ECharts、HTML5、JavaScript / ECharts gauge使用示例
https://blog.csdn.net/u012812482/article/details/51079890 1. 效果 2. 简介 1. 其中仪表的部分使用的是ECharts的gauge控件实 ...
- Ubuntu: Windows Help Tools For Ubuntu
Virtual Box https://www.virtualbox.org/wiki/Linux_Downloads 装不上Wine时直接装虚拟机吧.RTX真是个坑爹的东西,找不到替代的客户端 迅雷 ...