Scala, partial functions
问题 Is there any way to create a PartialFunction except through the case statement? I'm curious, because I'd like to express the following (scala pseudo ahead!)... val bi = BigInt(_) if (bi.isValidInt) bi.intValue ... as a partial function, and doing val toInt : PartialFunction[String, Int] = { case s if BigInt(s).isValidInt => BigInt(s).intValue } seems redundant since I create a BigInt twice. 回答1: Not sure I understand the question. But here's my attempt: Why not create an extractor? object