dimN method

List dimN(
  1. int dimension
)

This method returns the nth dimension of a tuple.

Implementation

List<dynamic> dimN(int dimension) {
  List<dynamic> result = [];
  List<dynamic> initialTuple = this.data[0];
  if (this.data.isEmpty == true) {
    throw 'Cannot call the nth dimension\nas the tuple has no contents.';
  } else {
    int actualDimension = dimension - 1;
    if (initialTuple.length > 2) {
      for (int i = 0; i < this.data.length; i++) {
        result.add(this.data[i][actualDimension]);
      }
    } else {
      throw 'Cannot call the nth dimension\nas the tuple has "0 < n < 2" elements.';
    }
  }
  return result;
}