In languages with support for unary addition, and in situations where a long list of operations is performed against sequential items in an array-like structure I might create a simple counter "int counter= 0;" and do the following:
someOperation(array[counter++]);
nextOperation(array[counter++]);
subsequentOperation(array[counter++]);
.. etc
What is an idiomatic way in scala to achieve similar behavior - i.e. avoid requiring hard-coded input array indices? Here is a specific example: a simple record parser method that converts a tab-separated call detail to a Call object. Not knowing any better way I did an ugly thing of putting in an AtomicInteger. But what is an acceptable way to do this?
Note: we can not simply do a collective operation here because some of the columns require ".toInt" processing and others do not.
def parseStringToCall(text: String) = {
val toks = text.split('\t')
val ix = new AtomicInteger(0)
new CallUpdate(
toks(ix.getAndIncrement), // callDate
toks(ix.getAndIncrement), // calledNumber
toks(ix.getAndIncrement), // callingNumbe
toks(ix.getAndIncrement), // cellTowersVi
toks(ix.getAndIncrement), // direction
toks(ix.getAndIncrement), // iMSI
toks(ix.getAndIncrement), // manufacturer
toks(ix.getAndIncrement), // phoneType
toks(ix.getAndIncrement), // reasonforDro
toks(ix.getAndIncrement).toInt, // weeknum
toks(ix.getAndIncrement), // firstCellTow
toks(ix.getAndIncrement), // lastCellTowe
toks(ix.getAndIncrement).toInt, // calls
toks(ix.getAndIncrement), // distinctCell
toks(ix.getAndIncrement), // droppedCall
toks(ix.getAndIncrement).toInt, // handovers
toks(ix.getAndIncrement).toInt, // setupTime
toks(ix.getAndIncrement).toInt // talkTime
)