Luke
09/25/2019, 1:11 PM(0 until width).forEach { x ->
(0 until height).forEach { y ->
println("($x, $y)")
}
}
I would like to write code similar to:
(width rangeBy height).forEach { (x, y) -> println("($x, $y)") }
Note that width
and height
don’t come from an iterable object in my case.streetsofboston
09/25/2019, 1:14 PMfun Pair<Int, Int>.forEach(block: (Int,Int)-> Unit) {
(0 until width).forEach { x ->
(0 until height).forEach { y ->
block(x, y)
}
}
}
...
(width to height).forEach { x, y-> println("$x, $y") }
Luke
09/25/2019, 1:34 PM