Last active
August 29, 2015 14:07
-
-
Save crakjie/bac3453cf51abbcd05da to your computer and use it in GitHub Desktop.
Enable getOrElse on collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.GenTraversableOnce | |
implicit class ImplicitGetOrElse[T]( seq: Seq[T] ) { | |
def getOrElse[B >: T]( or: => GenTraversableOnce[B] ) = { | |
if ( seq.isEmpty ) or else seq | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment