-
-
Save rossabaker/511426 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
final class RichAnyRef[T <:AnyRef](val value: T) extends Proxy { | |
def self: Any = value | |
def ? : Option[T] = Option(value) | |
def ?[R] ( func: (T=>R) ) : Option[R] = Option(value) map func | |
} | |
implicit def RichAnyRefWrapper[T <:AnyRef](x: T) = new RichAnyRef(x) | |
final class RichOption[T](val value: Option[T]) extends Proxy { | |
def self: Any = value | |
def | (other:T): T = value.getOrElse(other) | |
} | |
implicit def RichOptionWrapper[T](x: Option[T]) = new RichOption(x) | |
var x = "hello" | |
x.?.|("not set") | |
x.?( _.length ) | |
x = null | |
x.?.|("not set") | |
x.?( _.length ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment