Clue
Clue copied to clipboard
Allow other types of keys in renameable table destructuring feature
Clue supports renameable destructuring - local {a => b} = t
read as "assign t.a
to local b
" - but currently only identifier fields are allowed (names that can index tables through dot notation).
It would be nice if we can also use value types for the source field, similar to Lua letting you use any non-nil type as a table key.
local {[1] => a, [2] => b} = {"hello", "world"}
// -- now a is "hello" and b is "world"
local {[true] => c, ["string field"] => d} = {[true] = false, ["string field"] = "yes"}
// -- c is now false, d is now "yes"
Better too if the source key will support expressions in general
local {[4] => {[iter] => x, [iter+1] => y}} = points
// -- x would be the value of points[4][iter], y would be points[4][iter+1]
Additionally, a separate syntax for destructuring ~~arrays~~ sequential-index tables may be helpful too
local [x,y,z] = {1, 0, 64}
// -- x = 1, y = 0, z = 64
[...]
keys in destructuring was added, but the array destructuring would need to work too differently to be simply added to table destructuring, and would have to be added as its own thing...
unless I find a way.