Skip to content

Instantly share code, notes, and snippets.

@jackywyz
Created August 31, 2011 09:59
Show Gist options
  • Save jackywyz/1183213 to your computer and use it in GitHub Desktop.
Save jackywyz/1183213 to your computer and use it in GitHub Desktop.
Elvis operator
object Ternary {
implicit def coalescingOperator[T](pred: T) = new {
def ??[A >: T](alt: =>A) = if (pred == null) alt else pred
}
implicit def elvisOperator[T](alt: =>T) = new {
def ?:[A >: T](pred: A) = if (pred == null) alt else pred
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment