My logic is simple. I have the following text lines and convert them to a Map:
a-1.0
b-text
c-
d-
e-2.0
Please note that value could be null. Here is my way in Scala to do that:
var valueMap = scala.collection.mutable.Map[String,String]()
Source.fromFile("file/text").getLines().foreach(l=>{
var temp = l.split("-")
if(temp.size.equals(2)){
valueMap += (temp(0)->temp(1))
}else{
valueMap += (temp(0)->"")
}
})
It works but it's more like Java way istead of Scala way.
Anyone could help me with implementation in more functional or more Scala way?