Lukasz Kalnik
06/30/2022, 9:21 AMEither but with more subtypes?
I need something like this:
sealed class DataState<T> {
class Loading<T> : DataState<T>()
data class Error<T>(val error: CallError) : DataState<T>()
data class DataLoaded<T>(
val data: T
) : DataState<T>()
}
And I want only the DataLoaded subtype to behave as Either.Right (e.g. when using flatMap()) and all other subtypes behave as Either.Left, i.e. having early returns from flatMap().
I especially would like to have the monad comprehension syntax analogous to the either {} DSL (using .bind()).Lukasz Kalnik
06/30/2022, 9:23 AMdata I have to typecheck / cast everytime, which doesn't look elegant:
fun workWithData() {
val dataLoaded = (dataState as? DataLoaded) ?: return
val data = dataLoaded.data
}Youssef Shoaib [MOD]
06/30/2022, 9:32 AMDataLoadedLukasz Kalnik
06/30/2022, 9:36 AMsimon.vergauwen
06/30/2022, 9:51 AMsealed interface to define "layers", and then I can unite them with a common parent to closer they come to my API edge.Lukasz Kalnik
06/30/2022, 12:04 PM