Skip to content

Instantly share code, notes, and snippets.

@bijukunjummen
Created March 16, 2021 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bijukunjummen/c139e72b0e4417e90d67d58c6ebd8d0d to your computer and use it in GitHub Desktop.
Save bijukunjummen/c139e72b0e4417e90d67d58c6ebd8d0d to your computer and use it in GitHub Desktop.
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