IssueRaiser

Add typed tuples to GDScript

### Describe the project you are working on No projects at the moment due to life being an asshole, worked on some small projects before. ### Describe the problem or limitation you are having in your project The upcoming Typed Array doesn't have a case for tuples (fixed length, heterogeneous arrays). ### Describe the feature / enhancement and how it helps to overcome the problem or limitation Tuples would be a type alias for arrays. They have fixed-length and heterogeneous types, like in Python or Typescript. Technically, this would mean adding a type alias, (I think this is easy) and adding special cases for it (error on length manipulation, error on random access, ...). ### Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams ```gdscript var tuple_variable: Tuple[int, Node2D, String] = [17, some_node2d_var, "str"] tuple_variable[0] = 15 tuple_variable[1] = 15 # fails var invalid = tuple_variable[some_idx_var] # it can fail at compile time (safer) # or it can fail at run time if the index is out of bounds tuple_variable.append(5) # fails, tuples have fixed length func smal_tuple_func(arg: Tuple[int, Node2D]): ... func big_tuple_func(arg: Tuple[int, Node2D, String, int]): ... smal_tuple_func(tuple_variable) # works, last value is omited big_tuple_func(tuple_variable) # fails, last value is missing ``` ### If this enhancement will not be used often, can it be worked around with a few

Posted by FelipeSharkao on Jul 2, 2021, 1:09 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

reliability (Other)

Add typed tuples to GDScript

FelipeSharkaoJul 2, 2021, 1:09 PM

### Describe the project you are working on No projects at the moment due to life being an asshole, worked on some small projects before. ### Describe the problem or limitation you are having in your project The upcoming Typed Array doesn't have a case for tuples (fixed length, heterogeneous arrays). ### Describe the feature / enhancement and how it helps to overcome the problem or limitation Tuples would be a type alias for arrays. They have fixed-length and heterogeneous types, like in Python or Typescript. Technically, this would mean adding a type alias, (I think this is easy) and adding special cases for it (error on length manipulation, error on random access, ...). ### Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams ```gdscript var tuple_variable: Tuple[int, Node2D, String] = [17, some_node2d_var, "str"] tuple_variable[0] = 15 tuple_variable[1] = 15 # fails var invalid = tuple_variable[some_idx_var] # it can fail at compile time (safer) # or it can fail at run time if the index is out of bounds tuple_variable.append(5) # fails, tuples have fixed length func smal_tuple_func(arg: Tuple[int, Node2D]): ... func big_tuple_func(arg: Tuple[int, Node2D, String, int]): ... smal_tuple_func(tuple_variable) # works, last value is omited big_tuple_func(tuple_variable) # fails, last value is missing ``` ### If this enhancement will not be used often, can it be worked around with a few

Comments (0)

No comments yet. Start the discussion.

Comment on this issue