summaryrefslogtreecommitdiff
path: root/test/files/run/t6448.check
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-09-29 18:15:15 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-11-04 21:21:51 +0100
commitbc3dda2b0222d3b7cf3db491728b98f9b6110856 (patch)
treed71d81b7c443e75e12da82e9d6e8c53c84d31f1d /test/files/run/t6448.check
parent2c6777fd53b93b95a261aadc87a5cbc03c14d503 (diff)
downloadscala-bc3dda2b0222d3b7cf3db491728b98f9b6110856.tar.gz
scala-bc3dda2b0222d3b7cf3db491728b98f9b6110856.tar.bz2
scala-bc3dda2b0222d3b7cf3db491728b98f9b6110856.zip
SI-6448 Collecting the spoils of PartialFun#runWith
Avoids calling both `isDefinedAt` and `apply`. This pathological case that would benefit the most looks like: xs collect { case x if {expensive(); true} => x } The typical change looks like: - for (x <- this) if (pf.isDefinedAt(x)) b += pf(x) + foreach(pf.runWith(b += _)) Incorporates feedback provided by Pavel Pavlov: https://github.com/retronym/scala/commit/ef5430 A few more opportunities for optimization are noted in the `Pending` section of the enclosed test. `Iterator.collect` would be nice, but a solution eludes me. Calling the guard less frequently does change the behaviour of these functions in an obervable way, but not contravene the documented semantics. That said, there is an alternative opinion on the comment of the ticket: https://issues.scala-lang.org/browse/SI-6448
Diffstat (limited to 'test/files/run/t6448.check')
-rw-r--r--test/files/run/t6448.check32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/files/run/t6448.check b/test/files/run/t6448.check
new file mode 100644
index 0000000000..9401568319
--- /dev/null
+++ b/test/files/run/t6448.check
@@ -0,0 +1,32 @@
+
+=List.collect=
+f(1)
+f(2)
+List(1)
+
+=List.collectFirst=
+f(1)
+Some(1)
+
+=Option.collect=
+f(1)
+Some(1)
+
+=Option.collect=
+f(2)
+None
+
+=Stream.collect=
+f(1)
+f(2)
+List(1)
+
+=Stream.collectFirst=
+f(1)
+Some(1)
+
+=ParVector.collect=
+(ParVector(1),2)
+
+=ParArray.collect=
+(ParArray(1),2)