title: Scala function map
body: <p>I am just starting to learn scala, and perhaps I am a little ambitious. I wanted to map a <code>String</code> to a function that is from a <code>String</code> to <code>Boolean</code>. Unfortunately, I don't really understand the feedback I get from the compiler. Here is the code:</p>
  
  <pre><code>class StdRead {
      def read(key : Array[Int], value : Array[Int],seperator : Array[Char],
          filter : Map[Int, String =&gt; Boolean], write : String =&gt; Unit) {
      for( ln &lt;- stdin.getLines ) {
          val inarr = ln split seperator 
          for(i &lt;- key) {
              val func = filter get i //func : Option[(String) =&gt; Boolean]
              val f = func getOrElse Unit //f : java.lang.Object
              val res = func(inarr(i)) //Error, doesn't work
          }
          //more stuff        
      } 
  }
  </code></pre>
  
  <p>First of all, why do I get an <code>Option</code>, 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.</p>
  
  <p>Thanks in advance.</p>