Consider this piece of code
def foo(b: Int) = ???
val a = 3
foo(a)
It works fine of course, but let's say that later I decided that foo
should support an empty input, so I change it's signature to
def foo(b: Option[Int]) = ???
Now foo(a)
won't compile, because a
isn't an Option[Int]
, it's an Int
. So you have to say a = Some(3)
or foo(Some(a))
, which seems redundant to me.
My question is, why doesn't the language have an implicit conversion from T
to Some[T]
(and vice versa)?
Is it a good idea to implement one yourself?