Long term it would be nice if we could clean this up and remove the special casing of __call during iteration. This requires that all code that currently uses __call in iterators to migrate to __iter. Matter is one of very few (two for now based on our analytics) libraries that does that.
Would it be possible to specify __iter on iteratable objects? You should be able to do this in a way that doesn't break when __iter is not implemented by simply declaring it as a forwarding method, something like
function Iterator.__iter(self)
return self
end
(which will still call __call on every iteration after that, __iter is only called once before the iteration begins)
Alternatively you can return an actual iteration function from __iter which will be faster since __call calls are slower than regular function calls, but I haven't looked closely at Matter source to see if this would be easy to do. In either case the change would be backwards compatible if you don't touch __call so it can be implemented before __iter goes out of beta I believe.
Our implementation of
__iter
(RFC) currently respects__call
and treats it as a sign that we should not iterate through key/value pairs of the table to preserve backwards compatibility.__iter
is currently in Studio beta (https://developer.roblox.com/en-us/resources/release-note/Release-Notes-for-526).Long term it would be nice if we could clean this up and remove the special casing of
__call
during iteration. This requires that all code that currently uses__call
in iterators to migrate to__iter
. Matter is one of very few (two for now based on our analytics) libraries that does that.Would it be possible to specify
__iter
on iteratable objects? You should be able to do this in a way that doesn't break when__iter
is not implemented by simply declaring it as a forwarding method, something like(which will still call
__call
on every iteration after that,__iter
is only called once before the iteration begins)Alternatively you can return an actual iteration function from
__iter
which will be faster since__call
calls are slower than regular function calls, but I haven't looked closely at Matter source to see if this would be easy to do. In either case the change would be backwards compatible if you don't touch__call
so it can be implemented before__iter
goes out of beta I believe.