[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Filtering Iterator
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 22 Dec 2012 19:48:12 +0200
2012/12/22 Kevin Martin <kev82@khn.org.uk>:
>
> I want to write the following code:
>
> for a in carer:availBlocks() do
> --do something with a
> end
>
> I do not want to write:
>
> for a in carer:toProblem():availBlocks() do if carer:id() == a:carer():id() then
> --do something with a
> end
>
This can be done with coroutines.
function carer:availBlocks()
return coroutine.wrap(
function()
for a in self:toProblem():availBlocks() do
if self:id() == a:carer():id() then coroutine.yield(a)
end end end)
end