I am just starting to learn scala, and perhaps I am a little ambitious. I wanted to map a String to a function that is from a String to Boolean. Unfortunately, I don't really understand the feedback I get from the compiler. Here is the code:
class StdRead {
def read(key : Array[Int], value : Array[Int],seperator : Array[Char],
filter : Map[Int, String => Boolean], write : String => Unit) {
for( ln <- stdin.getLines ) {
val inarr = ln split seperator
for(i <- key) {
val func = filter get i //func : Option[(String) => Boolean]
val f = func getOrElse Unit //f : java.lang.Object
val res = func(inarr(i)) //Error, doesn't work
}
//more stuff
}
}
First of all, why do I get an Option, is that the only way to access the function. Secondly, why is the return of getOrElse an object? Shouldn't that be something I can use to invoke the function? It would be great if someone could give me a simple example as to what I need to do here.
Thanks in advance.