seqlua
diff README @ 41:54647a56a47a
Fixed third example of "write_lines" in README
author | jbe |
---|---|
date | Mon Aug 25 03:42:34 2014 +0200 (2014-08-25) |
parents | 21230b38d858 |
children | a862f3246b48 |
line diff
1.1 --- a/README Mon Aug 25 03:22:46 2014 +0200 1.2 +++ b/README Mon Aug 25 03:42:34 2014 +0200 1.3 @@ -63,20 +63,25 @@ 1.4 If one wanted to create a function that accepts either a sequence in form of a 1.5 table or an iterator function, then one might need to write: 1.6 1.7 - function write_lines(lines) 1.8 - local iter1, iter2, iter3 1.9 - if type(lines) == "function" then 1.10 - iter1 = lines 1.11 - else 1.12 - iter1, iter2, iter3 = ipairs(lines) 1.13 - end 1.14 - for i, line in iter1, iter2, iter3 do 1.15 + do 1.16 + local function write_line(line) 1.17 io.stdout:write(line) 1.18 io.stdout:write("\n") 1.19 end 1.20 + function write_lines(lines) 1.21 + if type(lines) == "function" then 1.22 + for line in lines do 1.23 + write_line(line) 1.24 + end 1.25 + else 1.26 + for i, line in ipairs(lines) do 1.27 + write_line(line) 1.28 + end 1.29 + end 1.30 + end 1.31 end 1.32 1.33 -Obviously, this isn't something we want to write in every function that accepts 1.34 +Obviously, this isn't something we want to do in every function that accepts 1.35 sequential data. Therefore, we usually decide for one of the two first forms 1.36 and therefore disallow the other possible representation of sequential data to 1.37 be passed to the function.