scala.runtime

AbstractPartialFunction

abstract class AbstractPartialFunction[-T1, +R] extends (T1) ⇒ R with PartialFunction[T1, R]

AbstractPartialFunction reformulates all operations of its supertrait PartialFunction in terms of isDefinedAt and applyOrElse.

This allows more efficient implementations in many cases:

This trait is used as a basis for implementation of all partial function literals.

Self Type
AbstractPartialFunction[T1, R]
Source
AbstractPartialFunction.scala
Since

2.10

Linear Supertypes
PartialFunction[T1, R], (T1) ⇒ R, AnyRef, Any
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. AbstractPartialFunction
  2. PartialFunction
  3. Function1
  4. AnyRef
  5. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new AbstractPartialFunction()

Abstract Value Members

  1. abstract def isDefinedAt(x: T1): Boolean

    Checks if a value is contained in the function's domain.

    Checks if a value is contained in the function's domain.

    x

    the value to test

    returns

    true, iff x is in the domain of this function, false otherwise.

    Definition Classes
    PartialFunction

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to any2stringadd[AbstractPartialFunction[T1, R]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (AbstractPartialFunction[T1, R], B)

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to ArrowAssoc[AbstractPartialFunction[T1, R]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  6. def andThen[C](k: (R) ⇒ C): PartialFunction[T1, C]

    Composes this partial function with a transformation function that gets applied to results of this partial function.

    Composes this partial function with a transformation function that gets applied to results of this partial function.

    C

    the result type of the transformation function.

    k

    the transformation function

    returns

    a partial function with the same domain as this partial function, which maps arguments x to k(this(x)).

    Definition Classes
    PartialFunctionFunction1
  7. def apply(x: T1): R

    Apply the body of this function to the argument.

    Apply the body of this function to the argument.

    returns

    the result of function application.

    Definition Classes
    AbstractPartialFunctionFunction1
  8. def applyOrElse[A1 <: T1, B1 >: R](x: A1, default: (A1) ⇒ B1): B1

    Applies this partial function to the given argument when it is contained in the function domain.

    Applies this partial function to the given argument when it is contained in the function domain. Applies fallback function where this partial function is not defined.

    Note that expression pf.applyOrElse(x, default) is equivalent to

    if(pf isDefinedAt x) pf(x) else default(x)

    except that applyOrElse method can be implemented more efficiently. For all partial function literals the compiler generates an applyOrElse implementation which avoids double evaluation of pattern matchers and guards. This makes applyOrElse the basis for the efficient implementation for many operations and scenarios, such as:

    • combining partial functions into orElse/andThen chains does not lead to excessive apply/isDefinedAt evaluation
    • lift and unlift do not evaluate source functions twice on each invocation
    • runWith allows efficient imperative-style combining of partial functions with conditionally applied actions

    For non-literal partial function classes with nontrivial isDefinedAt method it is recommended to override applyOrElse with custom implementation that avoids double isDefinedAt evaluation. This may result in better performance and more predictable behavior w.r.t. side effects.

    x

    the function argument

    default

    the fallback function

    returns

    the result of this function or fallback function application.

    Definition Classes
    PartialFunction
    Since

    2.10

  9. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  10. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. def compose[A](g: (A) ⇒ T1): (A) ⇒ R

    Composes two instances of Function1 in a new Function1, with this function applied last.

    Composes two instances of Function1 in a new Function1, with this function applied last.

    A

    the type to which function g can be applied

    g

    a function A => T1

    returns

    a new function f such that f(x) == apply(g(x))

    Definition Classes
    Function1
    Annotations
    @unspecialized()
  12. def ensuring(cond: (AbstractPartialFunction[T1, R]) ⇒ Boolean, msg: ⇒ Any): AbstractPartialFunction[T1, R]

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to Ensuring[AbstractPartialFunction[T1, R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: (AbstractPartialFunction[T1, R]) ⇒ Boolean): AbstractPartialFunction[T1, R]

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to Ensuring[AbstractPartialFunction[T1, R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean, msg: ⇒ Any): AbstractPartialFunction[T1, R]

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to Ensuring[AbstractPartialFunction[T1, R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean): AbstractPartialFunction[T1, R]

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to Ensuring[AbstractPartialFunction[T1, R]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  18. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  19. def formatted(fmtstr: String): String

    Returns string formatted according to given format string.

    Returns string formatted according to given format string. Format strings are as for String.format (@see java.lang.String.format).

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to Predef.StringFormat[AbstractPartialFunction[T1, R]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  20. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  21. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  22. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  23. def lift: (T1) ⇒ Option[R]

    Turns this partial function into a plain function returning an Option result.

    Turns this partial function into a plain function returning an Option result.

    returns

    a function that takes an argument x to Some(this(x)) if this is defined for x, and to None otherwise.

    Definition Classes
    PartialFunction
    See also

    Function.unlift

  24. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  25. final def notify(): Unit

    Definition Classes
    AnyRef
  26. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  27. def orElse[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]

    Composes this partial function with a fallback partial function which gets applied where this partial function is not defined.

    Composes this partial function with a fallback partial function which gets applied where this partial function is not defined.

    A1

    the argument type of the fallback function

    B1

    the result type of the fallback function

    that

    the fallback function

    returns

    a partial function which has as domain the union of the domains of this partial function and that. The resulting partial function takes x to this(x) where this is defined, and to that(x) where it is not.

    Definition Classes
    PartialFunction
  28. def runWith[U](action: (R) ⇒ U): (T1) ⇒ Boolean

    Composes this partial function with an action function which gets applied to results of this partial function.

    Composes this partial function with an action function which gets applied to results of this partial function. The action function is invoked only for its side effects; its result is ignored.

    Note that expression pf.runWith(action)(x) is equivalent to

    if(pf isDefinedAt x) { action(pf(x)); true } else false

    except that runWith is implemented via applyOrElse and thus potentially more efficient. Using runWith avoids double evaluation of pattern matchers and guards for partial function literals.

    action

    the action function

    returns

    a function which maps arguments x to isDefinedAt(x). The resulting function runs action(this(x)) where this is defined.

    Definition Classes
    PartialFunction
    Since

    2.10

    See also

    applyOrElse.

  29. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  30. def toString(): String

    Definition Classes
    Function1 → AnyRef → Any
  31. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. def [B](y: B): (AbstractPartialFunction[T1, R], B)

    Implicit information
    This member is added by an implicit conversion from AbstractPartialFunction[T1, R] to ArrowAssoc[AbstractPartialFunction[T1, R]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from PartialFunction[T1, R]

Inherited from (T1) ⇒ R

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from AbstractPartialFunction[T1, R] to any2stringadd[AbstractPartialFunction[T1, R]]

Inherited by implicit conversion StringFormat from AbstractPartialFunction[T1, R] to Predef.StringFormat[AbstractPartialFunction[T1, R]]

Inherited by implicit conversion Ensuring from AbstractPartialFunction[T1, R] to Ensuring[AbstractPartialFunction[T1, R]]

Inherited by implicit conversion ArrowAssoc from AbstractPartialFunction[T1, R] to ArrowAssoc[AbstractPartialFunction[T1, R]]

Ungrouped