Skip to content

Instantly share code, notes, and snippets.

@jedws
Forked from jroper/Schrödinger.scala
Created June 4, 2012 21:55
Show Gist options
  • Save jedws/2871066 to your computer and use it in GitHub Desktop.
Save jedws/2871066 to your computer and use it in GitHub Desktop.
Scala would be more fun if it had one of these...
final case class Schrödinger[+A, +B](private a: => A, private b: => B) extends Either[A, B] {
private lazy val actual : Either[A, B] =
if (new Random().nextBoolean())
Left(a)
else
Right(b)
def isLeft = actual.isLeft
def isRight = actual.isRight
def left = actual.left
def right = actual.right
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment