seqlua

changeset 28:3287510a35e3

Modified filter example in README (shows effect on alphabet() too)
author jbe
date Fri Aug 22 12:25:57 2014 +0200 (2014-08-22)
parents 18292ffaf2ac
children 2c4d9e44f704
files README
line diff
     1.1 --- a/README	Fri Aug 22 12:20:58 2014 +0200
     1.2 +++ b/README	Fri Aug 22 12:25:57 2014 +0200
     1.3 @@ -81,21 +81,22 @@
     1.4      end
     1.5  
     1.6      number_to_trues = filter(function(v)
     1.7 -      local type_v = type(v)
     1.8 -      if type_v == "string" then
     1.9 -        coroutine.yield(v)
    1.10 -      elseif type_v == "number" then
    1.11 +      if v == "a" then
    1.12 +        coroutine.yield("alpha")
    1.13 +      elseif v == "b" then
    1.14 +        coroutine.yield("beta")
    1.15 +      elseif type(v) == "number" then
    1.16          for i = 1, v do
    1.17 -          coroutine.yield(true)
    1.18 +          coroutine.yield("X")
    1.19          end
    1.20        end
    1.21      end)
    1.22  
    1.23 -    print((","):concat(number_to_trues{"a", "b", 3, "c"}))
    1.24 -    -- prints: a,b,true,true,true,c
    1.25 +    print((","):concat(number_to_trues{"a", 3, "b", "c", "d"}))
    1.26 +    -- prints: alpha,X,X,X,beta
    1.27  
    1.28      print((","):concat(number_to_trues(alphabet())))
    1.29 -    -- 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
    1.30 +    -- prints: alpha,beta
    1.31  
    1.32  
    1.33  C part of the library

Impressum / About Us