5 ms·
Option[Option[String]] != String??
by airless_bar 10y ago
Option[Option[String]] != String??
- junke 10y agoOption[Option[String]]? Is this a Church Numeral?
- SatvikBeri 10y agoMy impression, though I'm not sure, is that Kotlin simply won't allow you to do a double "??". Scala etc. will technically allow Option[Option[Something]], but in practice you would almost never want to use it, and can easily avoid it with flatMap.
- airless_bar 10y agoThe whole point of this was to show that Scala's types preserve the structure of the computation. It might not be very interesting in the Option[Option[String]] case but imagine Try[Either[String, Int]] or List[Future[Double]]. It's a very important distinction. Collapsing cases is one of the primary thing why exceptions sometimes get a bad rap, and Kotlin (and Ceylon) do the same with ? (and |, &) at the value level.