From a0c0f0949797a563c9583d0f82c0f390a999ec7d Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 23 Jan 2010 20:30:01 +0000 Subject: 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. --- src/library/scala/collection/Iterator.scala | 25 +++++++++++++++++++++++++ src/library/scala/xml/NodeSeq.scala | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/library') 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) -- cgit v1.2.3