summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/Iterator.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-08-17 20:00:23 +0000
committerPaul Phillips <paulp@improving.org>2009-08-17 20:00:23 +0000
commit32463342dcd5171d0f274dace6e4e4bfe6780cb0 (patch)
tree981a68d046fe763da718dc0f8d2142d9bb7bef81 /src/library/scala/collection/Iterator.scala
parent4c4040c93169aead8e353e345e961f3a0d80c6d3 (diff)
downloadscala-32463342dcd5171d0f274dace6e4e4bfe6780cb0.tar.gz
scala-32463342dcd5171d0f274dace6e4e4bfe6780cb0.tar.bz2
scala-32463342dcd5171d0f274dace6e4e4bfe6780cb0.zip
Added Iterator.continually, because
val it = Stream continually (foo) iterator it.foldLeft(...) grows without bound, and there needs to be a simple reliable way to repeatedly side effect.
Diffstat (limited to 'src/library/scala/collection/Iterator.scala')
-rw-r--r--src/library/scala/collection/Iterator.scala14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 4b83469df2..1335f37e8f 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -150,6 +150,18 @@ object Iterator {
def next(): Int = { val result = i; i += step; result }
}
+ /**
+ * Create an infinite iterator based on the given expression
+ * (which is recomputed for every element)
+ *
+ * @param elem the element composing the resulting iterator
+ * @return the iterator containing an infinite number of elem
+ */
+ def continually[A](elem: => A): Iterator[A] = new Iterator[A] {
+ def hasNext = true
+ def next = elem
+ }
+
/** A wrapper class for the `flatten `method that is added to class Iterator with implicit conversion @see iteratorIteratorWrapper.
*/
class IteratorIteratorOps[A](its: Iterator[Iterator[A]]) {
@@ -755,7 +767,7 @@ trait Iterator[+A] { self =>
* last step may be less than the given step, or both. What is
* guaranteed is that each element of the original iterator will
* appear in at least one sequence in the sliding iterator, UNLESS
- * the step size is larger than the windowsSize.
+ * the step size is larger than the windowSize.
*/
def sliding(windowSize: Int, step: Int = 1): Iterator[Sequence[A]] = {
require(windowSize >= 1 && step >= 1)