I noticed that scala loops differs from java loops:
//java: for(int i = 0; i < 2; i ++){ System.out.println("1loop"); for(int i = 0; i < 2; i ++){ System.out.println("2loop"); } } // output: 1loop 2loop 2loop ... And in Scala:
ranges.foreach{ range_line => print("1") transactions.foreach{ transaction_line => print("2") } } //output 111...22 Why it happening so? How to rearrange this nested loop to more scala-like style?
val ranges = scala.io.Source.fromInputStream(getClass.getResourceAsStream("/ranges.tsv")).getLines val transactions = scala.io.Source.fromInputStream(getClass.getResourceAsStream("/transactions.tsv")).getLines
rangesandtransactionsare (their types)?StreamstoArrayto the end of ranges and transactions initialization. But my be you can suggest me more sophisticated solution?