Last active
October 24, 2020 04:58
-
-
Save shankarshastri/880672e74b8ec2c61830078c34196027 to your computer and use it in GitHub Desktop.
ExploreUnionTypes
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 ExploreUnionTypes { | |
final case class Some[T](t: T) | |
final case class None() | |
type Option[T] = Some[T] | None | |
def toOption[T](t: T): Option[T] = { | |
if (t == null) None() else Some(t) | |
} | |
@main | |
def m = { | |
println(toOption("J")) | |
println(toOption(null)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment