File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,14 @@ libraryDependencies += "com.thoughtworks" %% "extractor" % "1.0.0"
1212
1313``` scala
1414import com .thoughtworks .Extractor ._
15+ import com .thoughtworks .Extractor ._
1516
16- // Convert a PartialFunction to a pattern
17+ // Define a PartialFunction
1718val pf : PartialFunction [Int , String ] = {
1819 case 1 => " matched by PartialFunction"
1920}
2021
21- // Convert an optional function to a pattern
22+ // Define an optional function
2223val f : Int => Option [String ] = { i =>
2324 if (i == 2 ) {
2425 Some (" matched by optional function" )
@@ -31,11 +32,11 @@ val f: Int => Option[String] = { i =>
3132val pf2 : PartialFunction [Int , String ] = f.unlift
3233
3334util.Random .nextInt(4 ) match {
34- case pf.extract(m) =>
35+ case pf.extract(m) => // Convert a PartialFunction to a pattern
3536 println(m)
36- case f.extract(m) =>
37+ case f.extract(m) => // Convert an optional function to a pattern
3738 println(m)
38- case pf2.extract(m) =>
39+ case pf2.extract(m) => // Convert a PartialFunction to a pattern
3940 throw new AssertionError (" This case should never occur because it has the same condition as `f.extract`." )
4041 case _ =>
4142 println(" Not matched" )
You can’t perform that action at this time.
0 commit comments