public
Last active

  • Download Gist
foo-example.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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))
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.