[Suggestion] table.map + more

Roblox should add a table.map function just like javascript

JS:

const reInitTbl=tbl=>tbl.map(lowerInitTbl);

Current LUA method:

function reInitTbl(tbl)
	local o={}for _,v in tbl do v=lowerInitTbl(v);end;return o;
end

Roblox LUA Suggestion:

function reInitTbl(tbl)
	return tbl.map(lowerInitTbl);
end -- or smth

I’m really used to array.map in javascript and would be good if Roblox could do the same :sob:

2 Likes

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()
2 Likes

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

1 Like

I know right and they should update UICorner so you can set the radius of each one of the 4 corners.

2 Likes

Luau used to have table.foreach() and table.foreachi(). They’ve since been deprecated.

There’s also some table util modules out that add a ton of extended functionality to tables

2 Likes

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”

1 Like

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

1 Like