As long as we have a PartialFunction[X,R] it's very easy to convert it to a function returning Option[R], e.g.
def pfToOptf[X, R](f: PartialFunction[X,R])(x: X) =
if (f.isDefinedAt(x)) Some(f(x))
else None
However, what if the task is opposite: suppose I have a function f getting X as an argument and returning Option[R] as a r...
While creating a map of String to partial functions I ran into unexpected behavior. When I create a partial function as a map element it works fine. When I allocate to a val it invokes instead. Trying to invoke the check generates an error. Is this expected? Am I doing something dumb? Comment out the check() to see the invocation. ...
Hi chaps,
I'm trying to design a couple of classes that inherit a partial function, but I don't seem to be able to get the syntax quite right. My superclass looks like this:
abstract class Controller {
val react:PartialFunction[Event,Unit]
}
And the subclass looks like:
class BoardRendererController(val renderer:BoardRenderer, ...
For lift development, I sometimes need to use match–case statements like the following. (Rewritten to plain scala for easier understanding.) One note to them: These are actually different partial functions, defined in different parts of the code, so it’s important that a case statement fails in or before the guard in order to have the ot...