Класс scala.UnliftOps
| Происхождение |
|---|
Конкретные методы
Исходник
def unlift: PartialFunction[A, B]
Преобразует функцию с возможностью отсутствия значения в частичную функцию.
| Пример |
В отличие от Function.unlift, этот метод UnliftOps.unlift может использоваться в экстракторах. 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")
}
|
|---|
© 2002-2022 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://scala-lang.org/api/3.1.1/scala/Function1$$UnliftOps.html