I'm parametrizing a query in Scala.
I have an array of strings with column names named colNames.
I want to create an string where for each name of the string the output is A.colName = B.colName and then join all the items in the array putting an " AND " string between each item.
Example of input
val colNames = Array("colName1","colName2")
val table1 = "A"
val table2 = "B"
Example of the desired output
"A.colName1 = B.colName1 AND A.colName2 = B.colName2"
In a non FP language I would do that with a for loop, but I don't know how to do it in Scala in a functional way.
"A"with"colName1"and"B"with"colName2"?colNamesis not controlled by the users, otherwise you'll quickly get requests along the lines ofcolNames = Array("colName1", "colName2 AND sendAllTehCoinzTo('BobbyTables') = 'success'").