Say, I have the following functions that allow me to create matrices:
inline fun <reified T> Matrix2D(w: Int, h: Int, init: (Int, Int) -> T) =
Array(w){ x -> Array(h){ y -> init(x, y) } }
inline fun <reified T> Matrix2D(w: Int, h: Int, value: T) =
Array(w){ Array(h){ value } }
// For example:
val m = Matrix2D(400, 400) { x, y ->
Color(x.toDouble() / 400.0, y.toDouble() / 400.0, 0.0)
}
I also don't want to allow for nullability, cause it's going to be a pain to deal with element access later.
How would I initialize such a matrix using multiple threads/coroutines, where each one initializes its own tile of the matrix, without allowing for nullability of the matrix cells?