Created
March 16, 2021 04:46
-
-
Save bijukunjummen/c139e72b0e4417e90d67d58c6ebd8d0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Try<out T> { | |
class Success<T>(private val result: T) : Try<T>() | |
class Failure<T>(private val throwable: Throwable) : Try<T>() | |
companion object { | |
fun <T> of(block: () -> T) = try { | |
Success(block()) | |
} catch (e: Throwable) { | |
Failure(e) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment