Last active
December 14, 2015 01:39
-
-
Save travisbrown/5008062 to your computer and use it in GitHub Desktop.
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
object FooExample { | |
sealed trait Foo { | |
def i: Int | |
} | |
private case class SecretFoo(i: Int) extends Foo | |
/* Without the explicit return type, we'd get this compiler error: | |
* | |
* <console>:14: error: private class SecretFoo escapes its defining scope... | |
* | |
*/ | |
def buildFoo(i: Int): Either[String, Foo] = if (i < 0) | |
Left("Need non-negative integer!") | |
else | |
Right(SecretFoo(i)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment