diff options
author | Martin Odersky <odersky@gmail.com> | 2010-01-11 15:48:20 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2010-01-11 15:48:20 +0000 |
commit | d163f6971b8b104b1f6f6a7737d7986f63038354 (patch) | |
tree | c49ffc9c65056d3a42a59c6e5780fc74910094fc | |
parent | 457fd685569f0d9cd3011e5f5aacf5d58fedb8bc (diff) | |
download | scala-d163f6971b8b104b1f6f6a7737d7986f63038354.tar.gz scala-d163f6971b8b104b1f6f6a7737d7986f63038354.tar.bz2 scala-d163f6971b8b104b1f6f6a7737d7986f63038354.zip |
Revised List#mapConserve so that it tests wrt e...
Revised List#mapConserve so that it tests wrt eq not ==.
-rw-r--r-- | src/library/scala/collection/immutable/List.scala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index 2c36161003..2088f3ac78 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -98,7 +98,7 @@ sealed abstract class List[+A] extends LinearSeq[A] /** Builds a new list by applying a function to all elements of this list. * Like `xs map f`, but returns `xs` unchanged if function - * `f` maps all elements to themselves (wrt ==). + * `f` maps all elements to themselves (wrt eq). * * Note: Unlike `map`, `mapConserve` is not tail-recursive. * @@ -106,15 +106,15 @@ sealed abstract class List[+A] extends LinearSeq[A] * @tparam B the element type of the returned collection. * @return a list resulting from applying the given function * `f` to each element of this list and collecting the results. - * @usecase def mapConserve[B](f: A => B): List[A] + * @usecase def mapConserve(f: A => A): List[A] */ - def mapConserve[B >: A] (f: A => B): List[B] = { + def mapConserve[B >: A <: AnyRef] (f: A => B): List[B] = { def loop(ys: List[A]): List[B] = if (ys.isEmpty) this else { val head0 = ys.head val head1 = f(head0) - if (head1 == head0) { + if (head1 eq head0.asInstanceOf[AnyRef]) { loop(ys.tail) } else { val ys1 = head1 :: ys.tail.mapConserve(f) |