iex
01/17/2020, 10:37 AMResult<T>
but which 1) Can return an arbitrary type as error and 2) Doesn't have a success payload. Here's the solution I came up with. I wonder if it can be expressed more elegantly?
sealed class EmptyResult<E> {
class Success<E> : EmptyResult<E>()
data class Failure<E>(val error: E): EmptyResult<E>()
}
fun foo(): EmptyResult<String> = EmptyResult.Success()
diesieben07
01/17/2020, 11:02 AMSuccess
a singleton:
sealed class EmptyResult<out E> {
object Success : EmptyResult<Nothing>()
data class Failure<out E>(val error: E): EmptyResult<E>()
}
fun foo(): EmptyResult<String> = EmptyResult.Success
hugo.matilla
01/17/2020, 11:11 AMhugo.matilla
01/17/2020, 11:11 AMStephan Schroeder
01/17/2020, 2:21 PMiex
01/17/2020, 3:56 PMobject
but had an issues with generics. In your code it's fixed 🙂iex
01/17/2020, 3:56 PMiex
01/17/2020, 3:57 PM