scala

PartialFunction

object PartialFunction extends AnyRef

A few handy operations which leverage the extra bit of information available in partial functions. Examples:

 import 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 }

Inherits

  1. AnyRef
  2. Any

Value Members

  1. def cond[T](x: T)(pf: PartialFunction[T, Boolean]): Boolean

    Creates a Boolean test based on a value and a partial function

  2. 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'

  3. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence

  4. def hashCode(): Int

    Returns a hash code value for the object

  5. def toString(): String

    Returns a string representation of the object