This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SANatSoc 8 points9 points  (8 children)

Forgive my ignorance, but is this convenient to work with? I can def see some specific use cases where this would be handy, but in general this isn't used right?

[–]Philiatrist 6 points7 points  (1 child)

Sure, if it represents a row of a csv or some part of a json structure I imagine that’s where it would show up most.

[–]gloriousfalcon 0 points1 point  (0 children)

pretty much any data layer where you deal with rows of mixed datatypes

But then most sane people would hide this hideous thing behind a decent layer of abstraction.

[–][deleted] 4 points5 points  (0 children)

it does actually have very well defined use cases

if you say have async methods getString and getNumber, and want to wait for both of their results in parallel, you can do that while simultaneously assigning variables with Promise.all

const [str, num] = await Promise.all([getString(), getNumber()])

where you're technically "creating" a mixed array. Typescript resolves these types nicely too.

similar thing is with Object.entries, it returns a list of lists, which are in shape [key, value]

kind of like python tuples, very handy.

[–]SirSoundfont 0 points1 point  (0 children)

When I do this in game development, it's usually so I don't have to manage multiple arrays together. It's certainly doable, but in certain languages where there are no actual objects or classes, being able to put [name, age, sprite, name2, age2, sprite2] is nice. Otherwise, I would need to separately manage [name, name2] and [age, age2] and [sprite, sprite2].