What\'s the difference between Some
and Option
?
scala> Some(true)
res2: Some[Boolean] = Some(true)
scala> val x: Option[Boolean]
From the functional programming perspective, given an arbitrary type T, the type Option[T] is an algebraic datatype with data constructors None and Some(x:T).
This is merely a coded way of saying that, if the type T consists of values t1, t2, t3, ...
then all the values of the type Option[T] are None, Some(t1), Some(t2), Some(t3), ...
Most everything else follows from this. E.g., if null is not a value of T, then Some(null) is not a value of Option[T]. This explains why
val x: Option[Boolean] = Some(null)
does not work, while
val x: Option[Null] = Some(null)
does.
Finally, specifically to Scala, there seems to be an additional quirk in that, "for convenience" one may say Option(null) when they mean None. I'd expect one can also say Option(t) when they mean Some(t).