Currently, the Object method call can be used like a getter with the option of providing several parameters.
Would it be feasible to allow using call as a generalised setter (for non-function objects)?
Use case: Consider an object a, that represents a matrix (see below):
final a = Matrix<int>(...);
The method call provides easy access to a certain matrix element:
To assign a value to the element, I currently use:
Would it be possible to add support for assigning a value using a similar syntax like the call function?
/// A data structure that stores data of type [T]
/// in a 2-dimensional array.
/// Matrix elements can be iterated in row-major order.
class Matrix<T> extends Iterable<T> {
final List<T> _data;
int _columns;
int _rows;
/// Number of columns.
int get columns => _columns;
/// The number of rows.
int get rows => _rows;
...
/// Returns the matrix element with row index [i] and column index [j].
/// Throws a [RangeError] if [i] or [j] are out of range.
T call(int i, int j) {
_checkRowIndex(i);
_checkColumnIndex(j);
return _data[columns * i + j];
}
/// Assign [value] to the matrix element with row index [i] and column index [j].
/// Throws a [RangeError] if [i] or [j] are out of range.
void assign(int i, int j, T value) {
_checkRowIndex(i);
_checkColumnIndex(j);
_data[columns * i + j] = value;
}
Currently, the
Objectmethodcallcan be used like a getter with the option of providing several parameters.Would it be feasible to allow using
callas a generalised setter (for non-function objects)?Use case: Consider an object
a, that represents a matrix (see below):The method
callprovides easy access to a certain matrix element:To assign a value to the element, I currently use:
Would it be possible to add support for assigning a value using a similar syntax like the call function?