UnliftOps

scala.Function1.UnliftOps
final implicit class UnliftOps[A, B] extends AnyVal

Attributes

Source
Function1.scala
Graph
Supertypes
class AnyVal
trait Matchable
class Any

Members list

Value members

Concrete methods

def unlift: PartialFunction[A, B]

Converts an optional function to a partial function.

Converts an optional function to a partial function.

Attributes

Example

Unlike Function.unlift, this UnliftOps.unlift method can be used in extractors.

val of: Int => Option[String] = { i =>
  if (i == 2) {
    Some("matched by an optional function")
  } else {
    None
  }
}
util.Random.nextInt(4) match {
  case of.unlift(m) => // Convert an optional function to a pattern
    println(m)
  case _ =>
    println("Not matched")
}
Source
Function1.scala