This may look obvious but I couldn't explain the No match available error . Below, you find a definition of a simple matching function I am using.
The same instructions inside the function run without an issue, however calling the function raises the error. Can you help me pinpoint the mistake ?
import scala.util.matching.Regex
def regexParsing(inputRecord:String, inputRegex:String, listOfFields:Seq[String], fieldsToRemove:Seq[String]): scala.collection.Map[String,Any] = {
val logPattern = new Regex(inputRegex, listOfFields:_*)
val result = logPattern.findAllIn(inputRecord)
val resultMap = result.groupNames.map(a => Map(a.toString -> result.group(a))).reduce(_++_)
return resultMap
}
val inputRecord = """s2222f"""
val inputRegex = """(.*)"""
val listOfFields = Seq("field")
val fieldsToRemove = Seq("field1", "field2")
// working
val logPattern = new Regex(inputRegex, listOfFields:_*)
val result = logPattern.findAllIn(inputRecord)
val resultMap = result.groupNames.map(a => Map(a.toString -> result.group(a))).reduce(_++_)
// not working
regexParsing(inputRecord, inputRegex, listOfFields, fieldsToRemove)
result.group(..)before the match iterator is materialized somehow - if you add something silly likeprintln(result)before creatingresultMapthis works (!).