Advertisement
alestane

FIltered iterator

Jan 25th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.25 KB | None | 0 0
  1. function filterLines(filter, source, ...)
  2.     local supply = coroutine.wrap(
  3.         function(filter, ...)
  4.             for line in ... do
  5.                 if filter(line) then
  6.                     coroutine.yield(line)
  7.                 end
  8.             end
  9.         end
  10.     )
  11.     supply(filter, source, ...)
  12.     return supply
  13. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement