Skip to content

Commit

Permalink
Merge pull request scala#6703 from Jasper-M/topic/fromFunction
Browse files Browse the repository at this point in the history
Reintroduce PartialFunction.apply as PartialFunction.fromFunction
  • Loading branch information
dwijnand authored Jun 1, 2018
2 parents 5c5b5df + 272bbd3 commit f16eacc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/library/scala/PartialFunction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ object PartialFunction {
case ff => new Unlifted(ff)
}

/** Converts an ordinary function to a partial function. Note that calling `isDefinedAt(x)` on
* this partial function will return `true` for every `x`.
* @param f an ordinary function
* @return a partial function which delegates to the ordinary function `f`
*/
def fromFunction[A, B](f: A => B): PartialFunction[A, B] = { case x => f(x) }

private[this] val constFalse: Any => Boolean = { _ => false}

private[this] val empty_pf: PartialFunction[Any, Nothing] = new PartialFunction[Any, Nothing] with Serializable {
Expand Down

0 comments on commit f16eacc

Please sign in to comment.