Skip to content

Instantly share code, notes, and snippets.

@shankarshastri
Last active October 24, 2020 04:58
Show Gist options
  • Save shankarshastri/880672e74b8ec2c61830078c34196027 to your computer and use it in GitHub Desktop.
Save shankarshastri/880672e74b8ec2c61830078c34196027 to your computer and use it in GitHub Desktop.
ExploreUnionTypes
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