Skip to content

Instantly share code, notes, and snippets.

@crakjie
Last active August 29, 2015 14:07
Show Gist options
  • Save crakjie/bac3453cf51abbcd05da to your computer and use it in GitHub Desktop.
Save crakjie/bac3453cf51abbcd05da to your computer and use it in GitHub Desktop.
Enable getOrElse on collection
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