You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Luau on May 2022 received an update which implemented generalized iteration. Generalized iteration no longer requires developers to write pairs or ipairs. From my knowledge, roblox-ts has only one way to iterate through arrays and dictionaries with the index/key, which is the pairs() function, but it compiles to pairs which is no longer preferred.
I would want a way to make compiler output the code snippet below. However, I don't think it is a simple matter of just changing the output for pairs function, as a developer would expect it to generate the Luau pairs function. Perhaps we could make a macro function that acts like pairs but compiles to generalized iteration.
localdictionary= {
a=1,
b=2,
c=3,
}
fori, vindictionarydoprint(i, v)
end
The text was updated successfully, but these errors were encountered:
Daw588
changed the title
Compile pairs() macro into generalized iteration instead of pairs
Implement generalized iteration for looping over dictionaries and arrays with the index
May 3, 2024
Daw588
changed the title
Implement generalized iteration for looping over dictionaries and arrays with the index
Implement generalized iteration for looping over dictionaries and arrays with the index/key
May 3, 2024
I never stated in the post that pairs should compile to generalized iteration. I was asking for a way to iterate through dictionaries and arrays that would produce generalized iteration in the compiler output.
We've considered this before by giving objects a generic [Symbol.iterator] K,V definition. I'm not sure what the result of the discussion was back then, I can have a look later.
Luau on May 2022 received an update which implemented generalized iteration. Generalized iteration no longer requires developers to write
pairs
oripairs
. From my knowledge, roblox-ts has only one way to iterate through arrays and dictionaries with the index/key, which is thepairs()
function, but it compiles to pairs which is no longer preferred.Input:
Output:
I would want a way to make compiler output the code snippet below. However, I don't think it is a simple matter of just changing the output for pairs function, as a developer would expect it to generate the Luau pairs function. Perhaps we could make a macro function that acts like pairs but compiles to generalized iteration.
The text was updated successfully, but these errors were encountered: