I have some code here that reads a file and converts it to a list of a type depending what is being passed to the function. The code for this function looks like so.
fun <R> readFile(path:String,convert:(String)->R): List<R> {
val reader = BufferedReader(FileReader(File(path)))
var line = reader.readLine()
val result = mutableListOf<R>()
while(line!=null) {
result.add(convert(line))
line = reader.readLine()
}
reader.close()
return result.toList()
}
The problem I have is that I am unsure sure what to pass into the variable convert. I am trying to return back a list of Person objects back. Below is the code I tried myself to hit the function readFile
val listOfPerson = readFile("path/person.txt","Person")
With this I'm getting an error with my Type. Intellij is flagging "Required (String) -> ???"