tag:blogger.com,1999:blog-3083788237966827171.post1065604339290117010..comments2023-11-03T04:16:02.546-07:00Comments on Jesper's Blog: A More Efficient OptionJesper Nordenberghttp://www.blogger.com/profile/07589508061874776093noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-3083788237966827171.post-31365953777603474392013-04-24T15:56:09.270-07:002013-04-24T15:56:09.270-07:00A problem with this implementation is that it can ...A problem with this implementation is that it can not handle Some(null), which is very common. E.g. call get on a Map[String,String] containing a null value.<br /><br />It is possible to cover that case using a private guard value for Some(null) or for None. <br /><br />See <a href="https://github.com/rklaehn/valueclassoption/blob/master/src/main/scala/scala2/Option.scala" rel="nofollow">github</a>.Unknownhttps://www.blogger.com/profile/03137389790993922565noreply@blogger.comtag:blogger.com,1999:blog-3083788237966827171.post-25345355281880286932013-03-12T16:37:28.255-07:002013-03-12T16:37:28.255-07:00One detail that is missed compared to the default ...One detail that is missed compared to the default scala Option is the Option.apply utility method. The case class that you have created will lose the type parameter if you try to use it like the original apply method, so you'd have to add in the type explicitly.Danhttps://www.blogger.com/profile/02192772456217563238noreply@blogger.comtag:blogger.com,1999:blog-3083788237966827171.post-14677890718105613902013-03-12T15:18:38.306-07:002013-03-12T15:18:38.306-07:00One disadvantage is that it takes more memory when...One disadvantage is that it takes more memory when a None value is upcasted because then the reference is boxed by the compiler (I've updated the memory comparison to include this case). However, this is not a very common case, and in the other cases it's more efficient. Other than that I don't see why the scala.Option class couldn't be turned into a value class.Jesper Nordenberghttps://www.blogger.com/profile/07589508061874776093noreply@blogger.comtag:blogger.com,1999:blog-3083788237966827171.post-50653972537697453162013-03-12T12:25:56.869-07:002013-03-12T12:25:56.869-07:00Is there any reason why this should not be the def...Is there any reason why this should not be the default option?decodeideashttps://www.blogger.com/profile/10719518403609200342noreply@blogger.com