Given:
def readLines(x: String): List[String] = Source.fromFile(x).getLines.toList
def toKVMap(fName : String): Map[String,String] =
readLines(fName).map(x => x.split(',')).map { case Array(x, y) => (x, y) }.toMap
I want to be able to take a string and a list of files of replacements and replace bracketed items. So if I have:
replLines("Hello",["cat"]) and cat contains ello,i!, I want to get back Hi!
I tried:
def replLines(inpQ : String, y : List[String]): String = y match {
case Nil => inpQ
case x::xs => replLines(toKVMap(x).fold(inpQ) {
case ((str: String), ((k: String), (v: String))) =>
str.replace("[" + k + "]", v).toString
}, xs)
}
I think the syntax is close, but not quite there. What have I done wrong?
<cond>and conclusion<conc>, the statement 'IF<cond>AND ("cat"contains"ello,i!"), THEN <conc>' is logically valid. So, for example, the statement "if I have:replLines("Hello",["cat"])and"cat"contains"ello,i!", every yellow rubber duck can program." is valid. But it is not very helpful, because from false premises, everything follows. Can you somehow convert your code into an MCVE that does not depend on external files? Right now, the question is unclear.