I have entry at file having four columns colA, colB, colC, colD. I need to read that file and create two immutable datastructure mappings.
colA -> (colB, colC, colD)
colB -> (colA, colC, colD)
Is there any way I can do that in one go. Using for comprehension I can create one Array and after iterating through it I can create two Maps. But it doesn't seems correct and efficient approach.Please guide me through.
Well what I am doing is as below
case class Mapping(col1: String, col2: String, col3: String, col4: String)
val columnList = for {
line <- io.Source.fromInputStream(getClass.getClassLoader.getResourceAsStream(file)).getLines() if (!(line startsWith ("#")))
val splittedArray: Array[String] = line.replaceAll(" ", "").split(",")
if (splittedArray.length == 4)
} yield Mapping(splittedArray(0), splittedArray(1), splittedArray(2), splittedArray(3))
val map1 = columnList.map(mapping=> (mapping.col1, mapping)).toMap
val map2 = columnList.map(mapping=> (mapping.col2, mapping)).toMap