aboutsummaryrefslogtreecommitdiff
path: root/tests/run/colltest6/CollectionTests_2.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-26 23:51:04 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-26 23:51:04 +0200
commit84466af8e3834e64bf350fe03976ee2176bb6916 (patch)
treee4024b32b1cb8a7f5f4d4cd44f5a68e5bcfc929f /tests/run/colltest6/CollectionTests_2.scala
parent0c489f549de620424e5cb65c082a28568cade389 (diff)
downloaddotty-84466af8e3834e64bf350fe03976ee2176bb6916.tar.gz
dotty-84466af8e3834e64bf350fe03976ee2176bb6916.tar.bz2
dotty-84466af8e3834e64bf350fe03976ee2176bb6916.zip
Further extension with LazyList
Demonstrates how to integrate lazy non-view collections in the framework.
Diffstat (limited to 'tests/run/colltest6/CollectionTests_2.scala')
-rw-r--r--tests/run/colltest6/CollectionTests_2.scala76
1 files changed, 75 insertions, 1 deletions
diff --git a/tests/run/colltest6/CollectionTests_2.scala b/tests/run/colltest6/CollectionTests_2.scala
index 659bfb953..3304ffb22 100644
--- a/tests/run/colltest6/CollectionTests_2.scala
+++ b/tests/run/colltest6/CollectionTests_2.scala
@@ -49,7 +49,7 @@ object Test {
println(xs9)
println(xs10)
println(xs11)
- println(xs12)
+ println(xs12)
println(xs13)
println(xs14)
println(xs15)
@@ -211,6 +211,79 @@ object Test {
println(xs16.view)
}
+ def lazyListOps(xs: Seq[Int]) = {
+ val x1 = xs.foldLeft("")(_ + _)
+ val y1: String = x1
+ val x2 = xs.foldRight("")(_ + _)
+ val y2: String = x2
+ val x3 = xs.indexWhere(_ % 2 == 0)
+ val y3: Int = x3
+ val x4 = xs.head
+ val y4: Int = x4
+ val x5 = xs.to(List)
+ val y5: List[Int] = x5
+ val (xs6, xs7) = xs.partition(_ % 2 == 0)
+ val ys6: Seq[Int] = xs6
+ val ys7: Seq[Int] = xs7
+ val xs8 = xs.drop(2)
+ val ys8: Seq[Int] = xs8
+ val xs9 = xs.map(_ >= 0)
+ val ys9: Seq[Boolean] = xs9
+ val xs10 = xs.flatMap(x => Cons(x, Cons(-x, Nil)))
+ val ys10: Seq[Int] = xs10
+ val xs11 = xs ++ xs
+ val ys11: Seq[Int] = xs11
+ val xs12 = xs ++ Nil
+ val ys12: Seq[Int] = xs12
+ val xs13 = Nil ++ xs
+ val ys13: Seq[Int] = xs13
+ val xs14 = xs ++ Cons("a", Nil)
+ val ys14: Seq[Any] = xs14
+ val xs15 = xs.zip(xs9)
+ val ys15: Seq[(Int, Boolean)] = xs15
+ val xs16 = xs.reverse
+ val ys16: Seq[Int] = xs16
+ println("-------")
+ println(x1)
+ println(x2)
+ println(x3)
+ println(x4)
+ println(x5)
+ println(xs6)
+ println(xs6.to(List))
+ println(xs7)
+ println(xs7.to(List))
+ println(xs8)
+ println(xs8.to(List))
+ println(xs9)
+ println(xs9.to(List))
+ println(xs10)
+ println(xs10.to(List))
+ println(xs11)
+ println(xs11.to(List))
+ println(xs12)
+ println(xs12.to(List))
+ println(xs13)
+ println(xs13.to(List))
+ println(xs14)
+ println(xs14.to(List))
+ println(xs15)
+ println(xs15.to(List))
+ println(xs16)
+ println(xs16.to(List))
+
+ import LazyList.#::
+ val xs17 = 1 #:: 2 #:: 3 #:: LazyList.Empty
+ println(xs17)
+ xs17 match {
+ case a #:: b #:: xs18 =>
+ println(s"matched: $a, $b, $xs18")
+ case _ =>
+ }
+ println(xs17)
+ println(xs17.to(List))
+ }
+
def main(args: Array[String]) = {
val ints = Cons(1, Cons(2, Cons(3, Nil)))
val intsBuf = ints.to(ArrayBuffer)
@@ -222,5 +295,6 @@ object Test {
viewOps(intsView)
stringOps("abc")
arrayOps(Array(1, 2, 3))
+ lazyListOps(LazyList(1, 2, 3))
}
}