var twoDee = new List(2).map((_) => new List(3));var twoDee = new List(2).mappedBy((_) => new List(3)).toList();var twoDee = new List.dimensions([2, 3]);Hey Bob. Wasn't there some talk of being able to overload operator() in dart? In C++ I would overload operator() to access a matrix element.
new Iterable.generate(2, (i) => new List(3)).toList();
If we had that on List, and not just on Iterable, it might work reasonably well. Though you can also just define a function
listWithDimensions(sizes) => ...
to make it more compact.
--
class Grid {
int w, h;
List data;
List cols;
Grid(this.w, this.h) {
data = new List.fixedLength(w * h);
cols = new List.fixedLength(w);
for (int x = 0; x < w; x++) {
cols[x] = new GridCol(data, x, w);
}
}
GridCol operator [](int x) {
return cols[x];
}
}
class GridCol {
int x, w;
List data;
GridCol(this.data, this.x, this.w);
Object operator [](int y) {
return data[x + y * w];
}
void operator []= (int y, var value) {
data[x + y * w] = value;
}
}
...
var g = new Grid(2, 3);
g[1][2] = 'foo';
print(g[1][2]);array[[10,20,30]]=5x=array[[10,20,30]]
And what is PROGRAM if not a multidimensional (fractal) array of functions, plus multidimensional (fractal) array of data?