[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why no for table-iterator like e. g. "hashpairs"?
- From: Tim Hill <drtimhill@...>
- Date: Tue, 5 Nov 2019 14:07:09 -0800
> On Nov 4, 2019, at 10:58 PM, bil til <email@example.com> wrote:
> Hi Tim + Coda,
> thank you for your support of lua. I fully agree, although newbee... .
> Just: could we bring the path of this discussion back to the point, that it
> would be VERY nice, that currently it seems to be possilbe to iterate
> through the hash part of some larger ipairs-table with a lua for loop in
> some acceptable efficiency?
As others have noted, what you are asking for is a way to manage a subset of a larger collection, which isn’t really a language function so much as a design problem. There are two ways you could approach this:
1. Segment the table into two tables, each with the parts you wish to iterate. You can pack them into one table as a “holder” if you want, and even do clever things with the containing table via a metatable to union-ice the two subtables when desired. (You could, for example, automatically segregate items amounts the subtables when they were added to the main table.)
2. Use an auxiliary table with values that are keys into the first table, and iterate THAT table over the subset of the first table.
Neither of these approaches need language changes, and are of course much more generic than just integer vs other keys.