Suppose I have the following code, is there any way to simplify this to more a beautify way?
var i = 0
val step = 100
val limitArr = new ArrayBuffer[(Int, Int)]
while (i < rddPartNumber) {
limitArr += ((i, i + step))
i += step
}
What you are doing is basically looping over a sequence of numbers. That can be expressed by mapping on a Range
val limits = (0 until rddPartNumber by step) map {i => (i , i + step)}
Or if you prefer for
syntax
for {i <- 0 until rddPartNumber by step}
yield (i, i + step)
Use Array.tabulate
for an interval from a
to rddPartNumber
as follows
Array.tabulate((rddPartNumber-a)/step) { i => (i*step, i*step+step) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With