Bernhard
10/21/2018, 2:53 PMMike
10/21/2018, 4:29 PMraulraja
10/21/2018, 6:39 PMraulraja
10/21/2018, 6:39 PMstreetsofboston
10/21/2018, 8:13 PMvalue?.left()
than if (value == null) Left(value) else null
, for example.Mike
10/22/2018, 12:21 AMstreetsofboston
10/22/2018, 4:16 AMOption
would be the presence/absence of a value. An Either
has a different purpose (often carrying either a real value (right) or an error/exceptional value (left)).Mike
10/22/2018, 11:12 AMraulraja
10/24/2018, 10:26 AMOption.toEither
which gives you back Either<Unit, A>
.
You can also adapt the absence to whatever other error type you need
value: Int? = 0
object MissingValue
val result: Either<MissingValue, Int> =
Option.fromNullable(value).toEither().mapLeft { MissingValue }