File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
src/main/scala/com/thoughtworks Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -6,30 +6,30 @@ package com.thoughtworks
66 * @example
77 {{{
88 import com.thoughtworks.Extractor._
9-
10- // Convert a PartialFunction to a pattern
9+
10+ // Define a PartialFunction
1111 val pf: PartialFunction[Int, String] = {
1212 case 1 => "matched by PartialFunction"
1313 }
14-
15- // Convert an optional function to a pattern
14+
15+ // Define an optional function
1616 val f: Int => Option[String] = { i =>
1717 if (i == 2) {
1818 Some("matched by optional function")
1919 } else {
2020 None
2121 }
2222 }
23-
23+
2424 // Convert an optional function to a PartialFunction
2525 val pf2: PartialFunction[Int, String] = f.unlift
26-
26+
2727 util.Random.nextInt(4) match {
28- case pf.extract(m) =>
28+ case pf.extract(m) => // Convert a PartialFunction to a pattern
2929 println(m)
30- case f.extract(m) =>
30+ case f.extract(m) => // Convert an optional function to a pattern
3131 println(m)
32- case pf2.extract(m) =>
32+ case pf2.extract(m) => // Convert a PartialFunction to a pattern
3333 throw new AssertionError("This case should never occur because it has the same condition as `f.extract`.")
3434 case _ =>
3535 println("Not matched")
You can’t perform that action at this time.
0 commit comments