From 8a9fd64129926eea35f7dca181242855f14e153f Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Thu, 20 Oct 2011 22:29:20 +0000 Subject: virtpatmat, hidden behind -Yvirtpatmat at least one imminent TODO: undo hardwired generation of if/then/else, and decide based on type whether to call flatMap/orElse or inline those methods from Option review by extempore --- test/files/run/virtpatmat_partial.scala | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/files/run/virtpatmat_partial.scala (limited to 'test/files/run/virtpatmat_partial.scala') diff --git a/test/files/run/virtpatmat_partial.scala b/test/files/run/virtpatmat_partial.scala new file mode 100644 index 0000000000..d30944efb4 --- /dev/null +++ b/test/files/run/virtpatmat_partial.scala @@ -0,0 +1,73 @@ +object Test extends App { + val a = Map("a" -> Some(1), "b" -> None) + println(a) + + val res = a collect {case (p, Some(a)) => (p, a)} + + // should uncurry to: + // val res: Map[String,Int] = a.collect[(String, Int), Map[String,Int]]( + // new PartialFunction[(String, Option[Int]),(String, Int)] { + // def apply(x0_1: (String, Option[Int])): (String, Int) = MatchingStrategy.OptionMatchingStrategy.runOrElse[(String, Option[Int]), (String, Int)](x0_1)( + // (x1: (String, Option[Int])) => { + // val o9: Option[(String, Int)] = ({ + // val o8: Option[(String, Option[Int])] = Tuple2.unapply[String, Option[Int]](x1); + // if (o8.isEmpty) + // MatchingStrategy.OptionMatchingStrategy.zero + // else + // { + // val o7: Option[Some[Int]] = if (o8.get._2.isInstanceOf[Some[Int]]) + // MatchingStrategy.OptionMatchingStrategy.one[Some[Int]](o8.get._2.asInstanceOf[Some[Int]]) + // else + // MatchingStrategy.OptionMatchingStrategy.zero; + // if (o7.isEmpty) + // MatchingStrategy.OptionMatchingStrategy.zero + // else + // { + // val o6: Option[Int] = Some.unapply[Int](o7.get); + // if (o6.isEmpty) + // MatchingStrategy.OptionMatchingStrategy.zero + // else + // MatchingStrategy.OptionMatchingStrategy.one[(String, Int)]((o8.get._1, o6.get).asInstanceOf[(String, Int)]) + // } + // } + // }: Option[(String, Int)]); + // if (o9.isEmpty) + // (MatchingStrategy.OptionMatchingStrategy.zero: Option[(String, Int)]) + // else + // o9 + // }) + // + // def isDefinedAt(x_1: (String, Option[Int])): Boolean = MatchingStrategy.OptionMatchingStrategy.isSuccess[(String, Option[Int]), (String, Int)](x_1)( + // (x1: (String, Option[Int])) => { + // val o9: Option[(String, Int)] = ({ + // val o8: Option[(String, Option[Int])] = scala.Tuple2.unapply[String, Option[Int]](x1); + // if (o8.isEmpty) + // MatchingStrategy.OptionMatchingStrategy.zero + // else + // { + // val o7: Option[Some[Int]] = if (o8.get._2.isInstanceOf[Some[Int]]) + // MatchingStrategy.OptionMatchingStrategy.one[Some[Int]](o8.get._2.asInstanceOf[Some[Int]]) // XXX + // else + // MatchingStrategy.OptionMatchingStrategy.zero; + // if (o7.isEmpty) + // MatchingStrategy.OptionMatchingStrategy.zero + // else + // { + // val o6: Option[Int] = scala.Some.unapply[Int](o7.get); + // if (o6.isEmpty) + // MatchingStrategy.OptionMatchingStrategy.zero + // else + // MatchingStrategy.OptionMatchingStrategy.one[(String, Int)](null.asInstanceOf[(String, Int)]) + // } + // } + // }: Option[(String, Int)]); + // if (o9.isEmpty) + // (MatchingStrategy.OptionMatchingStrategy.zero: Option[(String, Int)]) + // else + // o9 + // }) + // } + // ) + + println(res) +} -- cgit v1.2.3