Nice intro to partial functions

8 views
Skip to first unread message

Aaron

unread,
Jan 16, 2012, 4:02:39 PM1/16/12
to Leeds Scala User Group
Just stumbled onto a blog entry back from October, but the author does
a good job at introducing Partial Functions, in particular in regards
to collections:


http://ebruchez.blogspot.com/2011/10/scala-partial-functions-without-phd.html

Matt Russell

unread,
Jan 17, 2012, 4:19:10 AM1/17/12
to scala...@googlegroups.com
Partial functions are pretty sweet! A feature I've not found an excuse to use yet is partial functions for pluggable exception handling:

scala> val handler: PartialFunction[Throwable, String] = { case e => "exception occurred" }
handler: PartialFunction[Throwable,String] = <function1>

scala> try { throw new RuntimeException } catch handler
res11: String = exception occurred

-- Matt
Reply all
Reply to author
Forward
0 new messages