Re: Filtering Iterator
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Filtering Iterator
- From: Dirk Laurie <dirk.laurie@...>
- Date: 2012年12月22日 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