From 66a92814a61c62149a49335f65f4189763b43296 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 29 Nov 2010 23:00:07 +0000 Subject: The initial implementation of TraversableOnce c... The initial implementation of TraversableOnce could not supply concrete methods or even signatures for map and flatMap because they have different signatures in Iterator and TraversableLike. But we can take another approach which works out as nicely: 1) Create implicits which install those methods and flatten on TraversableOnce instances. 2) Generalize the signatures of flatten and flatMap to work with A => TraversableOnce[B] instead of A => Traversable[B]. And voila, you can mix and match Iterators and Traversables in a for comprehension, map, flatMap, and flatten, without the tedious process of sprinkling .iterator or .toList around to appease the compiler. No review. --- src/build/genprod.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/build/genprod.scala') diff --git a/src/build/genprod.scala b/src/build/genprod.scala index cc941051c7..4920100c1c 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -343,7 +343,7 @@ object TupleTwo extends Tuple(2) b.result } - def flatMap[B, To](f: (El1, El2) => Traversable[B])(implicit cbf: CBF[Repr1, B, To]): To = { + def flatMap[B, To](f: (El1, El2) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = { val b = cbf(coll1.repr) val elems2 = coll2.iterator @@ -454,7 +454,7 @@ object TupleThree extends Tuple(3) { b.result } - def flatMap[B, To](f: (El1, El2, El3) => Traversable[B])(implicit cbf: CBF[Repr1, B, To]): To = { + def flatMap[B, To](f: (El1, El2, El3) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = { val b = cbf(coll1.repr) val elems2 = coll2.iterator val elems3 = coll3.iterator -- cgit v1.2.3