Skip to content

Instantly share code, notes, and snippets.

@Garyfimo
Last active June 20, 2020 22:02
Show Gist options
  • Save Garyfimo/52c6e62a6c862ff4e672000e111f9235 to your computer and use it in GitHub Desktop.
Save Garyfimo/52c6e62a6c862ff4e672000e111f9235 to your computer and use it in GitHub Desktop.
sealed class ResultadoEvaluacion<out E, out V> {
data class Valor<out V>(val valor: V) : ResultadoEvaluacion<Nothing, V>()
data class Error<out E>(val error: E) : ResultadoEvaluacion<E, Nothing>()
companion object {
inline fun <V> build(function: () -> V): ResultadoEvaluacion<Exception, V> =
try {
Valor(
function.invoke()
)
} catch (ex: Exception) {
Error(
ex
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment