Personally I think Partial functions are great because you can chain
them ... see orEse. The other nice thing is pattern matching on
function arguments. For instance:

val x: PartialFunction[String,String] = {
 case "dog" => "bark"
}

this PF is defined only if the argument is "dog". For anything else
isDefined function returns false.But whenever you want to call a PF
you should first call the isDefinedAt. If in the example above we'd
use a complete function calling it with something else then a dog
you'll get a MatchError at runtime.

So you'd call the above

val arg = "dog"
if (x.isDefinedAt(arg)) {
  x(arg)
}

Br's,
Marius

On Dec 27, 2:29 am, "Charles F. Munat" <c...@munat.com> wrote:
> As a holiday gift to myself I am reading Programming in Scala from cover
> to cover. I've gotten as far as the pattern matching stuff and there's a
> discussion of partial functions. PiS says: "In general, you should try
> to work with complete functions whenever possible..."
>
> But I notice that the Lift code is filled with partial functions.
> They're all over the place.
>
> What is the benefit of using partial functions that outweighs the
> detriment of possible runtime errors? I'm trying to understand why
> partial functions might be useful.
>
> Thanks!
> Chas.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to