Skip to content

Instantly share code, notes, and snippets.

@mdread
Created October 22, 2012 00:05
Show Gist options
  • Save mdread/3929025 to your computer and use it in GitHub Desktop.
Save mdread/3929025 to your computer and use it in GitHub Desktop.
An Elvis operator aware of empty strings
object ElvisOP {
implicit def any2elvis(x: Any) = new ElvisOP(Option(x))
}
class ElvisOP(me: Option[Any]) {
def ?> (that: Any) = me match{
case Some(s: String) => s match {
case _ if s.isEmpty() => that
case _ => s
}
case Some(b: Boolean) => if(!b) that else b
case Some(s) => s
case None => that
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment