Description
The current record proposal provides no notation for accessing a single positional field:
Positional fields are not exposed as getters. Record patterns in pattern matching can be used to access a record's positional fields.
There are a couple of implications of this.
First, I think this means that there's significant asymmetry between named and positional fields, in that you can access a named field directly on the object, but you can't do so for a positional field. So you have a constant sized syntax for reading a single named field, but the only syntax for reading a positional field requires reading all of the fields (out into a pattern match) which is fairly verbose (even if you just use _
for all of the fields you don't care about).
Second, there's a semantic asymmetry in that you can presumably access named fields dynamically (and hence write code that is polymorphic over records with named fields) but not positional fields:
void printX(Record record) {
print(record as dynamic.x);
}
Should we provide a way to read a single positional field? e.g. record.0
etc?
cc @munificent @lrhn @eernstg @stereotype441 @natebosch @jakemac53