@lucastex posted about the Java Elvis operator, and I tried something in Scala to get the same effect.
I've just converted everything to a new Structural Type with the ?:
operator taking an object of the same type as argument. So Say:
implicit def toRockStar[B](v : B) = new {
def ?:(opt: => B) = if (v == null) opt else v}
val name: String = "Paulo" // example
Why name ?: "Lucas"
gets "Lucas"
and name.?:{"Lucas"}
gets Paulo
? The new Structural Type is supposed to return the initial value of anything if it is not null, that is, "Paulo"
in the above code.
I'm a bit confused. Any explanation?