summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-01-23 20:30:01 +0000
committerPaul Phillips <paulp@improving.org>2010-01-23 20:30:01 +0000
commita0c0f0949797a563c9583d0f82c0f390a999ec7d (patch)
tree59a21db321f764372f3ad85930c527f7a1571f0e /src/library
parentbb6e5958e63e3d70cd1f1a86f3fa0b5f3b670d8a (diff)
downloadscala-a0c0f0949797a563c9583d0f82c0f390a999ec7d.tar.gz
scala-a0c0f0949797a563c9583d0f82c0f390a999ec7d.tar.bz2
scala-a0c0f0949797a563c9583d0f82c0f390a999ec7d.zip
Another big REPL patch.
a proper commit message, I will just say it adds a couple of pretty frabjous features, in addition to cleaning up a whole bunch of questionable code. * Tab-completion now chains through intermediate results on fields and 0-arg methods * You can now define custom Completors which define their own contents. Details and demos to come in a wiki document about the repl.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/Iterator.scala25
-rw-r--r--src/library/scala/xml/NodeSeq.scala3
2 files changed, 27 insertions, 1 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 32525d59a6..7dbc39f5b7 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -1121,6 +1121,17 @@ trait Iterator[+A] { self =>
res.toList
}
+ /** Traverses this iterator and returns all produced values in a set.
+ * $willNotTerminateInf
+ *
+ * @return a set which contains all values produced by this iterator.
+ */
+ def toSet[B >: A]: immutable.Set[B] = {
+ val res = new ListBuffer[B]
+ while (hasNext) res += next
+ res.toSet
+ }
+
/** Lazily wraps a Stream around this iterator so its values are memoized.
*
* @return a Stream which can repeatedly produce all the values
@@ -1140,6 +1151,20 @@ trait Iterator[+A] { self =>
buffer
}
+ /** Traverses this iterator and returns all produced values in a map.
+ * $willNotTerminateInf
+ * @see TraversableLike.toMap
+ *
+ * @return a map containing all elements of this iterator.
+ */
+ def toMap[T, U](implicit ev: A <:< (T, U)): immutable.Map[T, U] = {
+ val b = immutable.Map.newBuilder[T, U]
+ while (hasNext)
+ b += next
+
+ b.result
+ }
+
/** Tests if another iterator produces the same valeus as this one.
* $willNotTerminateInf
* @param that the other iterator
diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala
index 17ea9228f6..02c1b6ece8 100644
--- a/src/library/scala/xml/NodeSeq.scala
+++ b/src/library/scala/xml/NodeSeq.scala
@@ -80,8 +80,8 @@ abstract class NodeSeq extends immutable.Seq[Node] with SeqLike[Node, NodeSeq] {
* @return ...
*/
def \(that: String): NodeSeq = {
+ def fail = throw new IllegalArgumentException(that)
def atResult = {
- def fail = throw new IllegalArgumentException(that)
lazy val y = this(0)
val attr =
if (that.length == 1) fail
@@ -104,6 +104,7 @@ abstract class NodeSeq extends immutable.Seq[Node] with SeqLike[Node, NodeSeq] {
NodeSeq fromSeq (this flatMap (_.child) filter cond)
that match {
+ case "" => fail
case "_" => makeSeq(!_.isAtom)
case _ if (that(0) == '@' && this.length == 1) => atResult
case _ => makeSeq(_.label == that)