# HG changeset patch # User jbe # Date 1408702619 -7200 # Node ID 8ff86106e2fe5d576e253a5a8857313c88598131 # Parent 44880bcfc3237b1f88aad24dc67e8fcad53a6600 Curried function "filter" in README diff -r 44880bcfc323 -r 8ff86106e2fe README --- a/README Thu Aug 21 21:32:01 2014 +0200 +++ b/README Fri Aug 22 12:16:59 2014 +0200 @@ -72,13 +72,15 @@ print(string.concat(",", alphabet())) -- prints: a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z - function filter(f, seq) - return coroutine.wrap(function() - for i, v in ipairs(seq) do f(v) end - end) + function filter(f) + return function(seq) + return coroutine.wrap(function() + for i, v in ipairs(seq) do f(v) end + end) + end end - function filterfunc(v) + number_to_trues = filter(function(v) local type_v = type(v) if type_v == "string" then coroutine.yield(v) @@ -87,9 +89,9 @@ coroutine.yield(true) end end - end + end) - for v in filter(filterfunc, {"a", "b", 3, "c"}) do + for v in number_to_trues{"a", "b", 3, "c"} do print(v) end -- prints: @@ -100,7 +102,7 @@ -- true -- c - print((","):concat(filter(filterfunc, {"a", "b", 3, "c"}))) + print((","):concat(number_to_trues{"a", "b", 3, "c"})) -- prints: a,b,true,true,true,c