Created
April 5, 2015 12:52
-
-
Save Sciss/be182d7cc2f21af2ef22 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
| object ? { | |
| implicit def some[A](x: A): ? [A] = new ? (Some(x)) | |
| implicit def wrap[A](opt: Option[A]): ? [A] = new ? (opt) | |
| implicit def unwrap[A](x: ? [A]): Option[A] = x.option | |
| } | |
| final case class ? [A](private val option: Option[A]) extends AnyVal { | |
| override def toString = option.toString | |
| def ? [B] (fun: A => B) : Option[B] = option map fun | |
| def !! : A = option.get | |
| } | |
| implicit class Elvis[A1](x: => A1) { | |
| def ?: [A <: A1](opt: Option[A]): A1 = opt getOrElse x | |
| } | |
| var b: ?[String] = "abc" | |
| b.?(_.length) | |
| val l = b.?(_.length) ?: -1 | |
| b.!!.length() | |
| b = None | |
| val m = b.?(_.length) ?: -1 | |
| b.!!.length() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment