First, don't use foreach
for this. foreach
is evil. Use map
instead.
Second, don't use var
s. val
s are OK in most cases.
Third, don't use mutable structures if you can.
Consideing this, here is what it can be converted to:
val valueMap = Source.fromFile("file/text").getLines().map(line => {
line.split("-") match {
case Array(k, v) => (k, v)
case Array(k) => (k, "")
}
}).toMap