On Sunday, 16 October 2016 at 13:58:51 UTC, Andrei Alexandrescu wrote:
I was thinking it would be handy if tuples had a way to access a field by name at runtime. E.g.:

Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";


In Scala you can do this:

def getUserInfo = ("Al", 42, 200.0)
val(name, age, weight) = getUserInfo

See http://alvinalexander.com/scala/scala-tuple-examples-syntax. You can also do the same thing in Kotlin and in Groovy (in Groovy it only works if static type checking is not turned on, though).

I fear if D in contrast has a solution for tuples like this:

Tuple!(int, "a", double, "b") t;
string x = condition ? "a" : "b";
double v = t.get!string(x, 3.14);

where variable names are mapped as strings it could harm the reputation of the language. People have something they could easily use as a sample to attack the language. These are harsh words, I know. Sorry for that. I only write this because I feel people should be advised not to do this. Real tuples or none. IMHO much better.

Reply via email to