summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/GenTraversableOnce.scala
diff options
context:
space:
mode:
authorStefan Zeiger <szeiger@novocode.com>2016-02-02 20:07:08 +0100
committerStefan Zeiger <szeiger@novocode.com>2016-02-04 11:32:31 +0100
commitf8d6814bb4fb0248d6121335e67eee8fde7ce455 (patch)
treefd09c8f8557151f3cf9818487e53a110ddaf8635 /src/library/scala/collection/GenTraversableOnce.scala
parentcc6fea6d30609b8879db1ecdbc288e4cdaa5b8d4 (diff)
downloadscala-f8d6814bb4fb0248d6121335e67eee8fde7ce455.tar.gz
scala-f8d6814bb4fb0248d6121335e67eee8fde7ce455.tar.bz2
scala-f8d6814bb4fb0248d6121335e67eee8fde7ce455.zip
SI-9624 Improve documentation for TraversableOnce
- Move the doc comment for `hasDefiniteSize` up from TraversableLike to GenTraversableOnce and improve it. - Add a note to `GenTraversableOnce.isEmpty` that implementations must not consume elements. - Clarify alternatives to subclassing TraversableOnce.
Diffstat (limited to 'src/library/scala/collection/GenTraversableOnce.scala')
-rw-r--r--src/library/scala/collection/GenTraversableOnce.scala20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala
index 244ff26397..4af2ca23be 100644
--- a/src/library/scala/collection/GenTraversableOnce.scala
+++ b/src/library/scala/collection/GenTraversableOnce.scala
@@ -67,6 +67,23 @@ trait GenTraversableOnce[+A] extends Any {
*/
def foreach[U](f: A => U): Unit
+ /** Tests whether this $coll is known to have a finite size.
+ * All strict collections are known to have finite size. For a non-strict
+ * collection such as `Stream`, the predicate returns `'''true'''` if all
+ * elements have been computed. It returns `'''false'''` if the stream is
+ * not yet evaluated to the end. Non-empty Iterators usually return
+ * `'''false'''` even if they were created from a collection with a known
+ * finite size.
+ *
+ * Note: many collection methods will not work on collections of infinite sizes.
+ * The typical failure mode is an infinite loop. These methods always attempt a
+ * traversal without checking first that `hasDefiniteSize` returns `'''true'''`.
+ * However, checking `hasDefiniteSize` can provide an assurance that size is
+ * well-defined and non-termination is not a concern.
+ *
+ * @return `'''true'''` if this collection is known to have finite size,
+ * `'''false'''` otherwise.
+ */
def hasDefiniteSize: Boolean
def seq: TraversableOnce[A]
@@ -81,6 +98,9 @@ trait GenTraversableOnce[+A] extends Any {
/** Tests whether the $coll is empty.
*
+ * Note: Implementations in subclasses that are not repeatedly traversable must take
+ * care not to consume any elements when `isEmpty` is called.
+ *
* @return `true` if the $coll contains no elements, `false` otherwise.
*/
def isEmpty: Boolean