I'm struggling with a case where I can have multip...
# arrow
d
I'm struggling with a case where I can have multiple kinds of errors. For example for one operation I could have NetworkError, EncryptionError and a GenericError (fallback for everything else uncovered by the other two). In other case I might have just NetworkError. I use Either to wrap the result. Left is used for errors, right for the success value. My question is is there a way I can specify that the left can be an arbitrary number of types (known at compile time)? Like Either can be Left or Right, is there something for more cases?
I believe union types is what I need, however this is not production ready yet, no?
p
For the generalised solution, yes
You can implement it as a new sealed hierarchy of classes wrapping each possibility
Or
Either<Either<Either
and make future self hate you hahaha
👍 1
😁 3
d
Thanks
Unfortunately I don't believe hierarchy of sealed classes would do, as the project is with multiple modules
p
You can make a hierarchy wrapping the classes on different modules. Think of them as inline classes.
Alternatively, copypaste some of these with Kotlin lambdas instead of Rx interfaces: https://github.com/pakoito/rxsealedunions
d
Interesting, thank you