I would like to know what the best Scala imitation of Groovy\'s safe-dereference operator (?.), or at least some close alternatives are?
I\'ve discussed it breifly o
Not mine but a coworker's
class NullCoalescer[T <: AnyRef](target: T) {
def ?? (other: T) =
if(target == null) other else target
}
object NullCoalescerConversions {
implicit def toNullCoalescer[T <: AnyRef](target: T): NullCoalescer[T] =
new NullCoalescer(target)
}
println (System.getProperty("maybe") ?? "definitely")