diff options
-rw-r--r-- | src/library/scala/Iterable.scala | 8 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/ListMap.scala | 15 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/library/scala/Iterable.scala b/src/library/scala/Iterable.scala index 42a5f2eb82..6ef8e2ec06 100644 --- a/src/library/scala/Iterable.scala +++ b/src/library/scala/Iterable.scala @@ -359,6 +359,14 @@ trait Iterable[+A] { addString(buf, start, sep, end).toString } + /** Returns a string representation of this iterable object. The string + * representations of elements (w.r.t. the method <code>toString()</code>) + * are separated by the string <code>sep</code>. + * + * @param sep separator string. + * @return a string representation of this iterable object. */ + def mkString(sep: String): String = this.mkString("", sep, "") + /** Write all elements of this string into given string builder */ def addString(buf: StringBuilder, start: String, sep: String, end: String): StringBuilder = { buf.append(start) diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index 782d471aa4..1705378846 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -79,13 +79,14 @@ class ListMap[A, +B] extends Map[A, B] { /** Returns an iterator over key-value pairs. */ - def elements: Iterator[Pair[A,B]] = new Iterator[Pair[A,B]] { - var self: ListMap[A,B] = ListMap.this - def hasNext = !self.isEmpty - def next: Pair[A,B] = - if (!hasNext) throw new NoSuchElementException("next on empty iterator") - else { val res = Pair(self.key, self.value); self = self.next; res } - } + def elements: Iterator[Pair[A,B]] = + new Iterator[Pair[A,B]] { + var self: ListMap[A,B] = ListMap.this + def hasNext = !self.isEmpty + def next: Pair[A,B] = + if (!hasNext) throw new NoSuchElementException("next on empty iterator") + else { val res = Pair(self.key, self.value); self = self.next; res } + }.toList.reverse.elements protected def key: A = throw new NoSuchElementException("empty map") protected def value: B = throw new NoSuchElementException("empty map") |