Permalink
Browse files

Implement Implicit Class with Extension Method

This extends support for headOption in 2.11 while allowing the inherent functionality provided by 2.12 to take precedence once 2.12 is released.
  • Loading branch information...
1 parent fb9a496 commit 03a22d315a658c547b3cdcc31a94f862c60ddb58 @ChristopherDavenport ChristopherDavenport committed Jul 21, 2016
Showing with 8 additions and 0 deletions.
  1. +8 −0 slick/src/main/scala/slick/util/ReadAheadIterator.scala
@@ -43,3 +43,11 @@ trait ReadAheadIterator[+T] extends BufferedIterator[T] {
} else throw new NoSuchElementException("next on empty iterator");
}
}
+
+object ReadAheadIterator {
+
+ /** Feature implemented in Scala library 2.12 this maintains functionality for 2.11 */
+ implicit class headOptionReverseCompatibility[T](readAheadIterator: ReadAheadIterator[T]){
+ def headOption : Option[T] = if (readAheadIterator.hasNext) Some(readAheadIterator.head) else None
+ }
+}

0 comments on commit 03a22d3

Please sign in to comment.