Scala Library
|
|
scala/PartialFunction.scala
]
object
PartialFunction
extends
AnyRefimport PartialFunction._ def strangeConditional(other: Any): Boolean = cond(other) { case x: String if x == "abc" || x == "def" => true case x: Int => true } def onlyInt(v: Any): Option[Int] = condOpt(v) { case x: Int => x }
Method Summary | |
def
|
cond
[T](x : T)(pf : PartialFunction[T, Boolean]) : Boolean
Creates a Boolean test based on a value and a partial function.
It behaves like a 'match' statement with an implied 'case _ => false'
following the supplied cases.
|
def
|
condOpt
[T, U](x : T)(pf : PartialFunction[T, U]) : Option[U]
Transforms a PartialFunction[T,U] `pf' into Function1[T, Option[U]] `f'
whose result is Some(x) if the argument is in pf's domain and None otherwise,
and applies it to the value `x'. In effect, it is a 'match' statement
which wraps all case results in Some(_) and adds 'case _ => None' to the end.
|
Methods inherited from AnyRef | |
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Method Details |
def
cond[T](x : T)(pf : PartialFunction[T, Boolean]) : Boolean
x -
the value to testpf -
the partial functionx
is in the domain of pf && pf(x) == truex -
the value to testpf -
the PartialFunction[T,U]
Scala Library
|
|