diff options
author | Christopher Davenport <ChristopherDavenport@outlook.com> | 2016-07-15 16:41:39 -0400 |
---|---|---|
committer | Christopher Davenport <ChristopherDavenport@outlook.com> | 2016-07-15 16:41:39 -0400 |
commit | 11688eb95b88f02c89c5974c3ce22290b57a5374 (patch) | |
tree | a2f5d9b46f12d74b58e7ae73ffea56505e3abc5f /src/library/scala/collection/BufferedIterator.scala | |
parent | 3c43a7bc389eba0d7d52ef0d0cdb19812c4a8a0f (diff) | |
download | scala-11688eb95b88f02c89c5974c3ce22290b57a5374.tar.gz scala-11688eb95b88f02c89c5974c3ce22290b57a5374.tar.bz2 scala-11688eb95b88f02c89c5974c3ce22290b57a5374.zip |
SI-9691 BufferedIterator should expose a headOption
This exposes a new API to the BufferedIterator trait. It will return the next element of an iterator as an Option. The return will be Some(value) if there is a next value, and None if there is not a next element.
Diffstat (limited to 'src/library/scala/collection/BufferedIterator.scala')
-rw-r--r-- | src/library/scala/collection/BufferedIterator.scala | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/library/scala/collection/BufferedIterator.scala b/src/library/scala/collection/BufferedIterator.scala index e6e97d584c..1424ef2fd0 100644 --- a/src/library/scala/collection/BufferedIterator.scala +++ b/src/library/scala/collection/BufferedIterator.scala @@ -24,5 +24,11 @@ trait BufferedIterator[+A] extends Iterator[A] { */ def head: A + /** Returns an option of the next element of an iterator without advancing beyond it. + * @return the next element of this iterator if it has a next element + * `None` if it does not + */ + def headOption : Option[A] = if (hasNext) Some(head) else None + override def buffered: this.type = this } |