Interesting suggestion! I also thought of something similar: a (lazy) iterator library, similar to Rust’s. After all, if we’re gonna do it, why not go all the way?
As such, to achieve what you wanted, we’d do something like:
local myNumbers = {1, 2, 3}
local squaredNumbers = iter(myNumbers).map(function(n)
return n * n
end).collect()
Honestly, I’m surprised this hasn’t been added yet considering all the updates they’ve been giving with Luau. I’d love to have some simple related methods like:
Map,
Filter,
ForEach,
etc.
If we could just take the entire JS array library and map it into Roblox that’d be fire
Oh weird, why did those get deprecated?
It is cool that there’s modules for it, I should probably look into that. Sucks that we need to add those dependencies though, feels like a lot of this stuff should just be in the standard library.
Edit: Looked into it, it’s because the implementation of them is pretty bad so they’re slower and can’t yield. So it is a good change to remove them, but it’d be a better change to implement an actual version of it (even if the backend just uses it as syntax sugar to apply the pairs loop).
It’s probably just because I’m used to TS but being able to have “table.forEach(f)” is so much nicer than “for i,v in pairs(table) do f(i,v) end”
It also had some useful implications like table.foreach(tbl, print).
But yeah a lot of the dependencies we need to add on our selves should be default.
and yeah ts has a ton of useful features that aren’t in Luau, that’s why so many people use RobloxTS