Created
August 31, 2011 09:59
-
-
Save jackywyz/1183213 to your computer and use it in GitHub Desktop.
Elvis operator
This file contains 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
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