diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-10-11 21:16:28 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-10-11 21:16:28 +0000 |
commit | 52ac60af8132ae7e42151d3012a9607d7cadaf95 (patch) | |
tree | 95085f9f535d20b6686399af1ba284bb74ac89d3 /gem/ex3.lua | |
parent | e394956cde629e24ecdd285c4c13c206891fcec4 (diff) | |
download | luasocket-52ac60af8132ae7e42151d3012a9607d7cadaf95.tar.gz luasocket-52ac60af8132ae7e42151d3012a9607d7cadaf95.tar.bz2 luasocket-52ac60af8132ae7e42151d3012a9607d7cadaf95.zip |
Tested each sample.
Diffstat (limited to 'gem/ex3.lua')
-rw-r--r-- | gem/ex3.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gem/ex3.lua b/gem/ex3.lua new file mode 100644 index 0000000..a43fefa --- /dev/null +++ b/gem/ex3.lua | |||
@@ -0,0 +1,15 @@ | |||
1 | local function chainpair(f1, f2) | ||
2 | return function(chunk) | ||
3 | local ret = f2(f1(chunk)) | ||
4 | if chunk then return ret | ||
5 | else return (ret or "") .. (f2() or "") end | ||
6 | end | ||
7 | end | ||
8 | |||
9 | function filter.chain(...) | ||
10 | local f = select(1, ...) | ||
11 | for i = 2, select('#', ...) do | ||
12 | f = chainpair(f, select(i, ...)) | ||
13 | end | ||
14 | return f | ||
15 | end | ||