sam
05/31/2019, 8:06 PMOption.fromNullable to be very verbose. Isn't the point of option that you may or may not have a nullable value, and so shouldn't Option(t) accept a nullable ?streetsofboston
05/31/2019, 8:07 PMOption<T?>, where null is a valid value and None would mean not even a value of null.sam
05/31/2019, 8:08 PMval name: String? = ... Option(name)sam
05/31/2019, 8:08 PMOption(null) I get a Nonestreetsofboston
05/31/2019, 8:10 PMvar nameFromServer : Option<String?>
...
nameFromServer = just(null) // no name
...
nameFromServer = none() // no value, not even a null-value
....
(not sure if the T in Option<T> is bound to Any or `Any?`…)streetsofboston
05/31/2019, 8:12 PMsam
05/31/2019, 8:13 PMsam
05/31/2019, 8:13 PMsam
05/31/2019, 8:13 PMsam
05/31/2019, 8:14 PMsam
05/31/2019, 8:14 PMstreetsofboston
05/31/2019, 8:15 PMOption can be defined to be able to accept null values as valid values, then Option(null) should not return a None (it should return Some(null))…. that is when you’d use fromNullable, i think, to get a None when the value is null.sam
05/31/2019, 8:16 PMsam
05/31/2019, 8:16 PMsam
05/31/2019, 8:16 PMstreetsofboston
05/31/2019, 8:17 PMsam
05/31/2019, 8:17 PMsam
05/31/2019, 8:17 PMstreetsofboston
05/31/2019, 8:19 PMsam
05/31/2019, 8:21 PMsam
05/31/2019, 8:21 PMsam
05/31/2019, 8:21 PMsam
05/31/2019, 8:22 PMoption.orElse { Option.fromNullable(name) }.orElse { Option.fromNullable(city) }pakoito
05/31/2019, 8:22 PMstreetsofboston
05/31/2019, 8:23 PMsam
05/31/2019, 8:24 PMstreetsofboston
05/31/2019, 8:27 PMsam
05/31/2019, 8:28 PMfromNullable whether it is an extension or not is still verbosesam
05/31/2019, 8:28 PM.option() to T?sam
05/31/2019, 8:28 PMOption(t) reallysam
05/31/2019, 8:29 PMstreetsofboston
05/31/2019, 8:30 PMfun <T> T?.toOption() that returns a Some or Nonesam
05/31/2019, 8:31 PMstreetsofboston
05/31/2019, 8:31 PMsam
05/31/2019, 8:31 PMsam
05/31/2019, 8:32 PMstreetsofboston
05/31/2019, 8:36 PMtoOption be defined as fun <T> T.toOptions(): Option<T>, where the extension-receiver no longer has a ? (fun <T> T?.toOptions(): Option<T>). I don’t think the ? is needed, since <T> upper-bound is already the nullable Any?raulraja
06/01/2019, 10:28 AMT is not constrained to Any, Just specifying T makes this function FORALL T including T?raulraja
06/01/2019, 10:29 AMraulraja
06/01/2019, 10:29 AMraulraja
06/01/2019, 10:29 AMraulraja
06/01/2019, 10:30 AMoption(1), some(1), right(1)raulraja
06/01/2019, 10:30 AMraulraja
06/01/2019, 10:31 AMOption.just(1)raulraja
06/01/2019, 10:32 AMraulraja
06/01/2019, 10:33 AM1.left() and Either.Left(1) or Left(1), or Either.left(1)raulraja
06/01/2019, 10:34 AMraulraja
06/01/2019, 10:34 AMraulraja
06/01/2019, 10:35 AMsam
06/01/2019, 4:58 PM