Hullaballoonatic
05/04/2019, 3:12 AMoperator fun get(rowIndices: IntRange, j: Int) = col(j)[rowIndices]
print(A[1..3, 0]) // < 1.0, 3.0, 1.0 >
operator fun set(i: Int, colIndices: IntRange, values: List<Double>) {
for (j in colIndices) this[i,j] = values[j]
}
A[2, 0..4] /= 2.0
print(A[2]) // < 1.5, 1.5, 1.5, 3.0, 3.0 >
operator fun set(rowIndices: IntRange, colIndices: IntRange, op: (Int, Int) -> Double) {
for (i in rowIndices)
for (j in colIndices)
this[i,j] = op(i, j)
}
A[1..2, 3..4] = { 0.0 }
You get the picture. They make me REALLY wish Kotlin allowed for rangeTo operators such as ..3
and 4..
that I could bound in the function or supply default arguments into the missing number since it ruins the prettiness of these Range getters/setters to do stuff like A[3..lastRowIndex, 2]
or A[5, 2 until n]
til
infix to be short for until
, even though it is far worse 😮