All Downloads are FREE. Search and download functionalities are using the official Maven repository.

application.Outcome.kt Maven / Gradle / Ivy

There is a newer version: 2.0.37
Show newest version
package application

data class Outcome(val result: ResultType?, val errorMessage: String = "") {
    fun  onSuccess(fn: (ResultType) -> Outcome): Outcome {
        return when {
            result != null -> fn(result)
            else -> Outcome(null, errorMessage)
        }
    }

    fun handleSuccess(fn: (ResultType) -> Unit) {
        when {
            result != null -> fn(result)
            else -> Outcome(null, errorMessage)
        }
    }

    fun onFailure(fn: (String) -> Unit) {
        if(result == null)
            fn(errorMessage)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy