object Extractor extends LowPriorityExtractor
Utilities to convert between A => Option[B]
, scala.PartialFunction and Extractor.
- Source
- Extractor.scala
import com.thoughtworks.Extractor._ // Define a PartialFunction val pf: PartialFunction[Int, String] = { case 1 => "matched by PartialFunction" } // Define an optional function val f: Int => Option[String] = { i => if (i == 2) { Some("matched by optional function") } else { None } } // Convert an optional function to a PartialFunction val pf2: PartialFunction[Int, String] = Function.unlift(f) util.Random.nextInt(4) match { case pf.extract(m) => // Convert a PartialFunction to a pattern println(m) case f.extract(m) => // Convert an optional function to a pattern println(m) case pf2.extract(m) => // Convert a PartialFunction to a pattern throw new AssertionError("This case should never occur because it has the same condition as `f.extract`.") case _ => println("Not matched") }
Example:
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- Extractor
- LowPriorityExtractor
- LowLowPriorityExtractor
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- All
Type Members
- implicit final class FunctionToExtractor[-A, +B] extends AnyRef
- Definition Classes
- LowLowPriorityExtractor
- implicit final class OptionFunctionToExtractor[-A, +B] extends AnyRef
- Definition Classes
- LowPriorityExtractor
- implicit final class OptionFunctionToSeqExtractor[-A, +B] extends AnyRef
- Definition Classes
- LowPriorityExtractor
- implicit final class PartialFunctionToExtractor[-A, +B] extends AnyRef
- sealed trait SeqExtractor[-A, +B] extends AnyRef
- Definition Classes
- LowPriorityExtractor
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()