temporarily reversing r22260; will be shortly re-committed in two separate portions.
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@22323 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
46cf65b7da
commit
428f291f72
|
@ -330,18 +330,17 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr]
|
|||
* for which `f(x)` equals `k`.
|
||||
*
|
||||
*/
|
||||
def groupBy[K](f: A => K): immutable.Map[K, Repr] = {
|
||||
val m = mutable.Map.empty[K, Builder[A, Repr]]
|
||||
def groupBy[K](f: A => K): Map[K, Repr] = {
|
||||
var m = Map[K, Builder[A, Repr]]()
|
||||
for (elem <- this) {
|
||||
val key = f(elem)
|
||||
val bldr = m.getOrElseUpdate(key, newBuilder)
|
||||
val bldr = m get key match {
|
||||
case None => val b = newBuilder; m = m updated (key, b); b
|
||||
case Some(b) => b
|
||||
}
|
||||
bldr += elem
|
||||
}
|
||||
val b = immutable.Map.newBuilder[K, Repr]
|
||||
for ((k, v) <- m)
|
||||
b += ((k, v.result))
|
||||
|
||||
b.result
|
||||
m map { case (k, b) => (k, b.result) }
|
||||
}
|
||||
|
||||
/** Tests whether a predicate holds for all elements of this $coll.
|
||||
|
|
|
@ -37,7 +37,7 @@ trait TraversableProxyLike[+A, +Repr <: TraversableLike[A, Repr] with Traversabl
|
|||
override def filterNot(p: A => Boolean): Repr = self.filterNot(p)
|
||||
override def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = self.collect(pf)(bf)
|
||||
override def partition(p: A => Boolean): (Repr, Repr) = self.partition(p)
|
||||
override def groupBy[K](f: A => K): immutable.Map[K, Repr] = self.groupBy(f)
|
||||
override def groupBy[K](f: A => K): Map[K, Repr] = self.groupBy(f)
|
||||
override def forall(p: A => Boolean): Boolean = self.forall(p)
|
||||
override def exists(p: A => Boolean): Boolean = self.exists(p)
|
||||
override def count(p: A => Boolean): Int = self.count(p)
|
||||
|
|
|
@ -216,7 +216,7 @@ self =>
|
|||
override def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[This, B, That]): That =
|
||||
newForced(thisSeq.scanRight(z)(op)).asInstanceOf[That]
|
||||
|
||||
override def groupBy[K](f: A => K): immutable.Map[K, This] =
|
||||
override def groupBy[K](f: A => K): Map[K, This] =
|
||||
thisSeq.groupBy(f).mapValues(xs => newForced(xs).asInstanceOf[This])
|
||||
|
||||
override def stringPrefix = "TraversableView"
|
||||
|
|
|
@ -135,7 +135,7 @@ extends SeqView[T, Coll]
|
|||
override def span(p: T => Boolean): (This, This) = (takeWhile(p), dropWhile(p))
|
||||
override def scanLeft[S, That](z: S)(op: (S, T) => S)(implicit bf: CanBuildFrom[This, S, That]): That = newForced(thisSeq.scanLeft(z)(op)).asInstanceOf[That]
|
||||
override def scanRight[S, That](z: S)(op: (T, S) => S)(implicit bf: CanBuildFrom[This, S, That]): That = newForced(thisSeq.scanRight(z)(op)).asInstanceOf[That]
|
||||
override def groupBy[K](f: T => K): collection.immutable.Map[K, This] = thisSeq.groupBy(f).mapValues(xs => newForced(xs).asInstanceOf[This])
|
||||
override def groupBy[K](f: T => K): collection.Map[K, This] = thisSeq.groupBy(f).mapValues(xs => newForced(xs).asInstanceOf[This])
|
||||
override def +:[U >: T, That](elem: U)(implicit bf: CanBuildFrom[This, U, That]): That = newPrepended(elem).asInstanceOf[That]
|
||||
override def reverse: This = newReversed.asInstanceOf[This]
|
||||
override def patch[U >: T, That](from: Int, patch: Seq[U], replaced: Int)(implicit bf: CanBuildFrom[This, U, That]): That = newPatched(from, patch, replaced).asInstanceOf[That]
|
||||
|
|
|
@ -29,8 +29,8 @@ object Test extends Application {
|
|||
val (o, e) = ten.partition(_ % 2 == 0)
|
||||
assert(o.size == e.size)
|
||||
val gs = ten groupBy (x => x / 4)
|
||||
val vs1 = (for (k <- gs.keysIterator; v <- gs(k).toIterable.iterator) yield v).toList.sorted
|
||||
val vs2 = gs.values.toList.flatten.sorted
|
||||
val vs1 = (for (k <- gs.keysIterator; v <- gs(k).toIterable.iterator) yield v).toList
|
||||
val vs2 = gs.values.toList.flatten
|
||||
// val vs2 = gs.values.toList flatMap (xs => xs)
|
||||
assert(ten.head == 1)
|
||||
assert(ten.tail.head == 2)
|
||||
|
|
Loading…
Reference in New Issue