Lukasz Kalnik
07/04/2022, 8:50 AMbind()
on the Either
contained in the `MutableStateFlow`'s value
here cannot be resolved. commonConnectorApi.renameControlDevice()
returns Either<CallError, Unit>
.Stylianos Gakis
07/04/2022, 9:15 AMDataMissing
a CallError
?Lukasz Kalnik
07/04/2022, 9:16 AMLukasz Kalnik
07/04/2022, 9:17 AMsealed class DataState<T> {
sealed class DataMissing : DataState<Nothing>()
object NotInitialized : DataMissing() {
operator fun invoke() = Left(NotInitialized)
}
data class Error private constructor(val error: CallError) : DataMissing() {
companion object {
operator fun invoke(error: CallError) = Left(Error(error))
}
}
data class DataLoaded<T> private constructor(val data: T) : DataState<T>() {
companion object {
operator fun <T> invoke(data: T) = Right(DataLoaded(data))
}
}
}
Lukasz Kalnik
07/04/2022, 9:17 AMbind()
be used only if the Left
type argument is the same for all calls?Alejandro Serrano Mena
07/04/2022, 9:19 AMeither
block can only have one error type, so all the calls to bind
need to be over the same type, or share a parent classStylianos Gakis
07/04/2022, 9:19 AMeither
block will be. Since the return type of your function is Either<CallError, Unit>, if you could bind in there with the left being a DataMissing
, what would you expect the return value to be? It has to confront to the type you said you’re returning.Lukasz Kalnik
07/04/2022, 9:20 AMeither
block with bind()
basically a flatMap
, so left type always has to be the same (only right type can be changed through the flatmapping).Lukasz Kalnik
07/04/2022, 9:20 AMStylianos Gakis
07/04/2022, 9:20 AMmapLeft { dataMissing -> dataMissing.toSomeCallError }.bind()
if there is such a mapping, or in general rethink what kind of error you want to return there and have it be of the same typeLukasz Kalnik
07/04/2022, 9:21 AMbind()
them both in the same either
block.Lukasz Kalnik
07/04/2022, 9:25 AMcontrolDevices.value
. But controlDevices.value
being in the state of DataMissing
is the result of the previous calls. They are not related to each other.
I just wanted to oversimplify things and the bind()
not resolving actually saved me from conflating a pure function call and a side effect.