S.
12/18/2022, 12:33 AMfun a() : Either<DomainError, Int> = either {
val a = getById(1).bind()
if (a.isPublic) return@either DomainError().left()
a.id
}
Why does return@either Error.left()
affect the Either.Right
here? I'm getting
Type mismatch. Required: Int Found: Either<DomainError, Nothing
. DomainError().left().bind()
would comply with the signature but warns that ``Returning type parameter has been inferred to Nothing implicitly` . What is the proper way to return early with a Either.Left in such a case?streetsofboston
12/18/2022, 12:37 AMstreetsofboston
12/18/2022, 12:41 AMS.
12/18/2022, 1:00 AMfun <B> shift(r: R): B
because it cannot be inferred. In Effect it states that both, A and R are mapped to B. DomainError().left().bind()
infers Nothing
but with a warning that it could produce runtime exceptions.julian
12/18/2022, 2:54 AMS.
12/18/2022, 9:14 AMokarm
12/18/2022, 12:01 PMshift
was changed to `Nothing`: https://github.com/arrow-kt/arrow/issues/2810
Arguably that should always have been the case - execution does not continue after shift
. It's akin to other Nothing
producers such as return
or throw
.