Created
June 4, 2012 15:59
-
-
Save jroper/2869212 to your computer and use it in GitHub Desktop.
Scala would be more fun if it had one of these...
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
final case class Schrödinger[+A, +B](a: A, b: B) extends Either[A, B] { | |
private var isleft = true | |
private var isright = true | |
lazy val actual : Either[A, B] = { | |
if (new Random().nextBoolean()) { | |
isright = false | |
Left(a) | |
} else { | |
isleft = false | |
Right(b) | |
} | |
} | |
def isLeft = isleft | |
def isRight = isright | |
def left = Either.LeftProjection(actual) | |
def right = Either.RightProjection(actual) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
needs moar laziness:
and you can make isLeft/isRight lazy vals too: